.htaccess issue under WAMP server - php

I'm trying to change some of the url names using htaccess.
ex;
mg_com_tr/index.php to mg_com_tr/home
I tried many different code samples inside my htaccess file, but nothing seems to work.
I never worked with the htaccess file before,so in order to test it, I found some example codes just for removing the ".php" extension.
When I try this code, I'm not getting any errors, but its not removing the .php extension either.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
The only working code I found is this one;
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
This removes the .php extension, however whatever I try I couldn't manage to change
http://localhost/mg_com_tr/index.php
into
http://localhost/mg_com_tr/home
I have a feeling that it has something to do with the path
Both the index.php and htaccess file is located at
D:\wamp\www\mg_com_tr\

try
RewriteEngine on
RewriteRule ^home index.php [NC,L]
or
RewriteRule ^home /index.php [NC,L]

Related

Weird problem in .htacess occurring after server change

I have a site with 3 scripts, namely viewgames.php, play.php and users.php present at the root directory. I also have a .htaccess file in the same (root) directory.
My .htaccess code that cleans URLs is :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^search/(.*)$ ./viewgames.php?search=$1
RewriteRule ^category/(.*)$ ./viewgames.php?cat=$1
RewriteRule ^users/(.*)$ ./users.php?action=$1
RewriteRule ^play/(.*)$ ./play.php?gn=$1
RewriteRule ^([a-z]+)\/?$ $1.php [NC]
ErrorDocument 404 /pagenotfound.php
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
When I was developing in localhost (XAMPP), I got no problem in accessing the clean URLs (using the above htaccess code) such as localhost/MySite/play/foo, localhost/MySite/category/action, localhost/MySite/search/lolol or localhost/MySite/users/myaccount.
It clearly means that the above .htaccess code was working like a charm in my localhost server. Then I uploaded the above code to a shared Apache-based linux server, and encountered some weird problems -
https://example.com/category/blabla was working fine, and so was https://example.com/search/blabla
But the URLs https://example.com/play/xyz and https://example.com/users/anyaction stopped working. By that I mean, the page was loading fine, the site was there, but no $_GET values were passed to the PHP script. Thus, I am not able to get the value of parametes gn and action. (see above code)
I even tried by var_dump-ing the $_GET array in the scripts, and they returned an empty array, meaning that no values were sent to the script.
Please check my .htaccess code. I am completely and utterly new to .htaccess, and the above code is merely a copied one. I will really appreciate any help in the matter.
Have it like this:
ErrorDocument 404 /pagenotfound.php
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^search/(.*)$ viewgames.php?search=$1 [L,QSA,NC]
RewriteRule ^category/(.*)$ viewgames.php?cat=$1 [L,QSA,NC]
RewriteRule ^users/(.*)$ users.php?action=$1 [L,QSA,NC]
RewriteRule ^play/(.*)$ play.php?gn=$1 [L,QSA,NC]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)/?$ $1.php [L,NC]
It is important to keep MultiViews options off to avoid content negotiation feature causing issues for mod_rewrite module.

Request exceeded the limit of 10 internal redirects due to probable configuration error

I know that this question has been asked a lot, but nothing I've seen so far worked.
I have a wp in root, running from subdirectory (I like things clean). I also a few subdomains running from subdirectories in root (eg. public_html/sample.com). I get the error only on subdomains that are pure HTML and CSS. They don't use any platform.
Here's my .htaccess from root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Things I've tried:
1) Comment out all RewriteRule - solves the problem, but then my wp doesn't work. It gives 404 error when I go to any posts or pages.
2) Changed the .htaccess to the following (courtesy of Scott Yang):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L,QSA]
</IfModule>
but that didn't change anything.
3) I also tried commenting out and pasting new code from other questions, quite on random, but it's the same story.
Any ideas?
Cheers
I've found a solution.
In the root directory for the subdomain, in the .htaccess add the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
Rewrite Rule ^([^.]+)$ $1.php [NC,L]
This is how you can get rid of .php from the end of URL.
Replace .php with .html and it also gets rid of .html
For some reason, this fixes the problem.
Cheers
EDIT:
This solved the problem, but it didn't remove the .html from the URL. Below worked perfectly
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Cheers

Rewrite rule in subdirectory

Rewrite rule does not work on remote host in subdirectory.
While in production phase, I had this directory http://localhost/prj/. I used RewriteRule to "hide" and "load" PHP files without extension. This is the .htaccess I've used:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
So, that worked fine, I've developed the project and I wanted to upload it to my VPS for remote use and such. The thing is, the project is still in beta, and I don't keep it in root directory ATM but at subdirectory /beta/, so now, this my URL right now is like this: http://example.com/beta/.
Yet when I tried to access that URL, the index.php is automatically loaded, but when I access for example file play.php as http://example.com/beta/play it doesn't work but it worked while the project was in production.
This is what I have tried:
To use RewriteBase to /beta/
RewriteBase /beta/
To use different options
Options All -Indexes -MultiViews
To use directory before actual RewriteRule
RewriteRule ^/beta/(.*)$ $1.php
To use operatives [L, QSA]
Example:
Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
Options All -Indexes -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/beta/(.*)$ $1.php [L,QSA]
Returned error is 404 Not found.
Edit: I'm I supposed to have too inside apache2.conf?
Try this in /beta/.htaccess:
Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/beta/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

Having problems with RewriteRule and .htaccess

I'm having a problem with my .htaccess. This is the code:
RewriteEngine On
Options -MultiViews
Options +FollowSymlinks
#Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
#Profile
RewriteRule ^profile/([a-zA-Z0-9_-]+)-([0-9]+)/([a-zA-Z0-9_-]+)$ profile.php?one=$1&two=$2&three=$3
I want to remove the .php extension, and create a seo-friendly URL with /profile.php. The problem comes when I try to access to http://website.com/profile/1/2/3, I get 500 Error. But if I remove the code which removes php extension, then, it works well, but of course, the .php extension is showed.
So... what's wrong in this code? I checked over and over and I really don't find any bugs... thanks.
I think problem is not using L flag (marking Last rule).
Replace your code with this:
RewriteEngine On
Options +FollowSymlinks -MultiViews
#Profile
RewriteRule ^profile/([\w-]+)/([\w-]+)/([\w-]+)/?$ profile.php?one=$1&two=$2&three=$3 [L,QSA]
#Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

.htaccess redirect works, but not rewrite

here is my .htaccess file, it works because the first rewriterule correctly redirects .html -> .php, but I am hoping to remove the .php extension also. if anyone could help me correct my code here I'd appreciate it.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.html$ http://vbwtest.comeze.com/$1.php [R,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
Try this.This will rewrite all your requests.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
Remove the R flag from your rewrite rule:
RewriteRule ^(.+)\.html$ http://vbwtest.comeze.com/$1.php [NC]
The R in [R,NC] tells it to redirect instead of just rewriting.

Categories