Question

I'm a beginner using htaccess and I don't know how to do what I want. I'd like to understand what I'm doing so I'd really appreciate if you can help me give me some advices for ver (very!) beginners... :) I'd like to: Redirect xxx.php, xxx.html or any extension to xxx (without extension) Now, my htaccess is

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

and it works but just if I write xxx. But if I write xxx.php (I see the page :(, I'd like to redirect to xxx) and if I write xxx.html it doesn't show nothing.

Finally. I've like to rewrite variables to friendly links i.e. If I have xxx.php?id=1 > I would like to redirect to xxx/username

Thank you in advance Best wishes and merry christmas! :)

Était-ce utile?

La solution

Try adding these rules to your htaccess file:

RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
RewriteRule ^ /%1 [L,R=301]

If you need to do the same with with .html extensions, then change the php part of that condition to (php|html?).

Autres conseils

Try this:

I use this code already.

Rule:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

Put this in your htaccess file && then check for files without extension.

Thanks

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top