I have a question regarding htaccess configuration win a PHP Project
I have this code to use redirection
DirectoryIndex src/client/index.php
Redirect /app/about http://localhost/app/?p=about
Redirect /app/contact http://localhost/app/?p=contact
Inside src/client/index.php I check the GET[p] to include the page requested.
It works... but I dont want to modify the htaccess file each time I add a new page.
I would like to implement something like this but it doesnt work, Im pretty sure I have syntax errors
Redirect ^/app/(.*) http://localhost/app/?p=$1
Thanks for your time :)
You just need to use RedirectMatch:
RedirectMatch ^/app/(.*) http://localhost/app/?p=$1
Related
I need to use .htaccess to remove /amp from a certain URL structure. I have incoming links that look like this:
https://domain/store/amp and https://domain/store/product/amp
In both cases, the /amp on the end results in 404 errors. I just need to get rid of it, because fixing the problem at the source is not currently an option. I intend to put the .htaccess in the /store/ directory path.
I have looked around for similar examples and tried to modify them, but rewrites make my head spin in short order. Thanks for the help.
You can use this Redirect
RedirectMatch 301 ^/(.+)amp$ /$1
I am Using XAMPP Server.
I have a folder or project named test in my htdocs.
I want to redirect user to redirect to newfile.htm when user access oldfile.htm direcly using htaccess.
I wrote below code in mine htaccess file but its not working
RewriteEngine on
Redirect 301 /oldfile.htm /newfile.htm
Kindly Guide me.
Redirect directive is part of apache alias module. You don't need to write RewriteEngine on to use Redirect. The reason why your Redirect failed is because you are a relative test path, you need to specify a full/absolute path in Redirect.
Redirect 301 /test/oldfile.html /test/newfile.html
should work. If the problem presists, Try clearing your browser cache and make sure you dont have other conflicting redirects in htaccess.
If user request existing php code, which I placed right in the root:
domain.com/images/pic1.jpg
domain.com/anyphp.php
domain.com/someapp/somecode.php
domain.com/anything.someExt
etc
don't do anything,leave as it, they are working good.
But if he simply enter domain.com -> send him to domain.com/myNewApp/index.php, which is my cool new app. Don't rewrite the URL to domain.com/index.php because it is for my existing app.
I expect the answer may be super simple but I am just giving up trying
DirectoryIndex oxwall/index.php
Simple but it works
Do you have access to the Apache conf file? If so:
RewriteEngine on
RedirectMatch ^/(.*)$ http://example.com/myNewApp/index.php
Should work.
Edit: This rewrite won't work. I never used the regex-capture. And I misread what you wanted. It looks like you found an answer, but this should still work if you change the regex to:
RewriteEngine on
RedirectMatch ^/$ http://example.com/myNewApp/index.php
Check out this page for more re-writey goodness:
http://httpd.apache.org/docs/current/rewrite/remapping.html
I'm working on fixing all my URL's to be shorter with 301 redirects. I have fix almost all of them, however there is a url that is ending with .cfm that will not rewrite.
FROM: http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.cfm
TO: http://www.mydomain.com/story/resources/health/page/168/page.html
If I change /page.cfm to /page.html then the rewrite will work.
Here is the rewrite rule that works for my other urls
RewriteRule ^index.cfm/catlink/([a-zA-Z0-9/-]+)([/])pagelink/([a-zA-Z0-9/-]+)([/])sublink/([a-zA-Z0-9/-]+)([/])art/([a-zA-Z0-9/-]+)(.*)$
http://localhost/index.cfm?page=moved&cat=$3&subcat=$5&article=$7&story=$8 [R=301]
Why does it work when the URL ends with .html but not when it ends with .cfm? What am I doing wrong?
This is current link and will not work:
http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.cfm
If I manually change the end of it to .html, I can get it to work:
http://www.mydomain.com/index.cfm/catlink/17/pagelink/7/sublink/34/art/41/rec/1/page.html
The issue is that Apache httpd is passing it off to Tomcat before Apache looks at the .htaccess. To test this, move your rewrite rules into your vhost. If they work, then that's what the problem was.
First off, change your the first part of your RewriteRule to be the following, more concise expression:
^index.cfm/catlink/(\d+)/pagelink/(\d+)/sublink/(\d+)/art/(\d+)/(.*)$
I believe that alone might resolve the issue. However, if it does not, and you don't care about the rest of the URL, try the following:
^index.cfm/catlink/(\d+)/pagelink/(\d+)/sublink/(\d+)/art/(\d+)/
Note: this removes the anchor ($) and therefore allows the URL to be open ended.
i need to redirect temporally a domain to a subdomain, this is my code for .htaccess:
Redirect 302 / http://m.domain.com/
this works great, but i have some subdirectories like: http://domain.com/photos, the code above redirects this way: http://m.domain.com/photos
i have a lot of subdirs and sub-subdirs, how i can redirect successfully all the subdirs to the same subdomain? (http://m.domain.com/)
Check out this post, I think it might help you. It looks like all you'd need to do is change your redirect to look something like:
Redirect 302 ^/.+/.*$ http://m.domain.com/
.htaccess redirect loop! All subdirectories to root
Hey, this is a tool for generating the redirect code, and lets you choose how the final URL looks, without knowing regex. Might help you.