PHP URL Rewrite doesn't work on specific server - php

My URL rewrite works perfectly on my testing server, but not on the live server.
I contacted the support team and they told me that mod_rewrite is already enabled on my hosting plan.
Here is my .htaccess file
RewriteEngine On
RewriteRule ^index.html$ index.php [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ work-tag.php?d=$1&t=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ work-tag.php?d=$1&t=$2
RewriteRule ^([a-zA-Z0-9_-]+)$ work.php?d=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ work.php?d=$1
Anything wrong?
Thanks

I got the same problem, but if you was asked about turned mode_rewrite - check it. I was told the same but I didn't find my htaccess working so I checked it by myself. And I found that mod_rewrite was still off.
phpinfo();
and have a look at the "Loaded Modules". If you see it so the server is not a problem. And need to go futher.

I finally fixed it by adding the following line as a friend suggested.
RewriteBase /
Thanks for your follow-up guys :)

Related

URI is considered to be lowercased in htaccess. What might be wrong?

I have been battling with this problem for a while. Suppose I go to website.com/one/tWo. In PHP $_SERVER['REQUEST_URI'] is one/tWo. I thought this had something to do with Apache URL rewriting so I checked .htaccess and removed everything and only left:
RewriteEngine On
RewriteRule ^one/two http://www.gosomewhereelse.com [R=301,L]
To my surprise, when trying 'one/tWo', Apache actually redirects me to www.gosomewhereelse.com.
Just to be clear, there is no redirection that happens from 'one/tWo' to 'one/two'. The URL doesn't change in the address bar and it still has the uppercase character but it's still matching with ^one/two
I tried everything I could think of and couldn't find a solution.
This works:
RewriteCond %{REQUEST_URI} ^/one/tWo$
RewriteRule ^(.*)$ http://www.gosomewhereelse.com [R=301,L]
This also works:
RewriteRule ^one/t[W]o http://www.gosomewhereelse.com [R=301,L]
It turns out that it's not related to apache or PHP. The problem is from a third party software.

.htaccess mod rewrite and MAMP

having issues with what i think is linked to the mod rewrite in mamp.
The rewrite works fine on the live server, but im working locally with MAMP and getting issues.
The problem is linked to this:
I rewrite the following URL:
http://localhost/BuildSanctuary-Dev/viewbuild/64/three-fiddy-z/1
That should rewrite as:
http://localhost/BuildSanctuary-Dev/viewbuild.php?id=64&title=three-fiddy-z&page=1
The issue is that i get a 404 for page not found.
The requested URL /viewbuild.php was not found on this server.
Which it clearly is... but if i visit just /viewbuild.php it works fine.
The rewrite in the .htaccess is:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
Any ideas? I have done the research and everything in the apache conf is showing as Allowing All...
Thanks.
Your rewriterule redirects to /viewbuild.php and not /BuildSanctuary-Dev/viewbuild.php:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /BuildSanctuary-Dev/viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
A mabye better variant would be to put the .htaccess into the /BuildSanctuary-Dev/ folder and use a relative path as redirect:
RewriteBase /BuildSanctuary-Dev
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]

mod_rewrite for URL with two URL-parameters

I want to be able to open the following url
http://example.com/login/12345
and in the background, it should load:
http://example.com/index.php?endpoint=login&access_key=12345
Obviously, I have tried many htaccess generators to create an appropriate RewriteRule set.
For example the following (from: http://www.generateit.net/mod-rewrite/index.php):
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?endpoint=$1&access_key=$2 [L]
Even though I know for a fact that .htaccess and mod_rewrite is enabled on my server (i tried to setup a test to redirect all requests from example.com to example2.com using htaccess and mod_rewrite, and it worked), I can't get this to work.
I have now spent nearly 2 hours to find for a solution on stackoverflow and other websites, but all my attempts failed.
I hope someone can help me find out the correct way to rewrite my url in the above example.like explained above.
Thanks a lot in advance!
Try with this:
RewriteEngine On
RewriteRule ^([^\/]*)/([^\/]*)$ /index.php?endpoint=$1&access_key=$2 [L]
#-Added-these---^--------^
When tested, here is the result:
Add this to the .htaccess file in your DOCUMENT_ROOT
Assuming login is not variable
RewriteEngine On
RewriteRule ^login/(\d+)$ index.php?endpoint=login&access_key=$1 [L,NC,DPI]
** If login is variable**
This is in case you want to redirect not only for login, but also for urls such as http://example.com/housenumber/12345
RewriteEngine On
RewriteRule ^([^/]+)/(\d+)$ index.php?endpoint=$1&access_key=$2 [L,NC,DPI]
Tested on actual Apache 2.2 and 2.4 :)

Using mod_rewrite to pass requests to CodeIgniter in a subfolder

I'm trying to pass requests from the root of my url to a subfolder without redirecting using mod_rewrite. (Note: I'm doing this on Rackspace Cloud Sites.)
I took the CI .htaccess, moved it up to the root folder, and changed it from this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|public|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
to this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|public|robots\.txt)
RewriteBase /ci/
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
Which gives me an internal server error. I don't believe this sort of this has an error log, which is probably why I've always considered mod_rewrite to be alchemy.
Maybe you can see what's going wrong?
Thanks!
Its not the mod_rewrite, its the server. I was able to run that no problem on my server. If you could provide a url, I can look more. But as it stands, it seems to be the server its running on.

Rewrite rule in WAMP

I am using a WAMP Server. I need to apply rewrite rule for the pages in my local system. I have enabled the rewrite_rule from the WAMP icon at Task bar.
My Website path in local system is http://localhost/Kitty_Enfin/.
http://localhost/Test/index.php -> http://localhost/Test/home
http://localhost/Test/index.php?do=main -> http://localhost/Test/main
http://localhost/Test/index.php?do=profile&uid=1 -> http://localhost/Test/profile/1
Above are the pages I need to rewrite.
My question is: where I need to place the .htaccess file?
Whether in www/ or www/Test
What is the .htaccess Rewrite rule for the above
It will be more helpful if anyone helps on the Following issue.
Thank you for your reply. When I used the above it not worked for me. But I used another rewrite rule which works for the first two:
RewriteRule ^([^/\.]+)/?$ /\Test/\index\.php [L] - Working
(http://localhost/Test, http://localhost/Test/index)
RewriteRule ^([^/\.]+)/?$ /\Test/\index.php?do=$1 [L] - Working
(http://localhost/Test/main)
RewriteRule ^profile/([^/\.]+)?$ /\Test/\index.php?do=profile&uid=$1 - Working but the CSS and other scripts are not work here.
And also the links in the pages are http://localhost/Test/profile/ instead of http://localhost/Test/.
Do you have any idea on this issue? Please correct me if I did anything wrong.
Do you have any idea on this issue. Please correct me any thing i did wrong
Thanks
RewriteRule ^/?index.php home/
RewriteRule ^/?index.php?do=(\w*) $1/
RewriteRule ^/?index.php?do=(\w*)&uid=(\w*) $1/$2
place the .htaccess in "Test" folder
I can only answer this from your clue

Categories