RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ $1.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/([^/]+)/$ books.php?id=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/([^/]+)$ books.php?id=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/ books.php [QSA]
Everything works when I type: localhost/name
but breaks if I type: localhost/name/
What's wrong with my .htaccess and how do I add support "/"
You don't need 2 rules and your 2nd rule has invalid regex anyway. Try this rule:
Options -MultiViews
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^books/([^/]+)/?$ books.php?id=$1 [L,NC,QSA]
RewriteCond %{DOCUMENT_ROOT}/myproject/$1\.php -f [NC]
RewriteRule ^([^/]+)/?$ $1.php [L]
Related
I'm trying to do a RewriteRule in .htacess but it's not working and I don't know why.
This is my code
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1/$2 [R=301,L]
RewriteRule ^agencia/agencia-marketing-digital-bh$ /agencia/section.php?id=$1 [L]
How it should work:
User acess www.mysite.com/agencia-marketing-digital-bh.php and it should change to www.mysite.com/agencia/agencia-marketing-digital-bh.php
Can someone please tell me what I'm doing wrong?
I have this problem, I have this url example.com/directory/fotos/index.php?u=username and what I need to do is change it to
example.com/username/fotos
I already have a rule in htacces which changes the directory to username in case a username is found in index.php
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ directory/index.php?u=$0&%{QUERY_STRING} [L]
Which ouputs example.com/someusername
How can I do a new rule for the above case without conflicting with the current rule?
This should do:
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/([^/]+)/fotos/?
RewriteRule ^([^/]+)/?$ /directory/index.php?u=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/directory/fotos/?
RewriteRule ^([^/]+)/fotos/?$ /directory/fotos/index.php?u=$1 [L,QSA]
I want to change some rules in .htaccess file write now my url is like this www.example.com/d/somthing.htm and some another pages with www.example.com/category.htm now i want to change them in this way www.example.com/index.php?d=somthing what i have to do.
My current .htaccess content are:-
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} ^/p\/[a-z][a-z]\/[[:print:]]+\.htm$
#RewriteRule \/p\/([a-z][a-z])\/([[:print:]]+)\.htm$ /index.php?p=$2&lang=$1 [L]
#RewriteRule \/p\/([a-z][a-z])\/([[:print:]]+)\.htm$ /index.php?p=$2&lang=$1 [L]
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/p\/[[:print:]]+\.htm$
RewriteRule \/p\/([[:print:]]+)\.htm$ /index.php?p=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/s\/[a-z][a-z]\/[0-9]+\/.*$
RewriteRule \/s\/([a-z][a-z])\/([0-9]+)\/.*$ /category.php?action=something&value=$2&lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/s\/[0-9]+\/.*$
RewriteRule \/s\/([0-9]+)\/.*$ /category.php?action=something&value=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/n\/[a-z][a-z]\/[0-9]+\/.*$
RewriteRule \/n\/([a-z][a-z])\/([0-9]+)\/.*$ /novel.php?action=more&value=$2&lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/n\/[0-9]+\/.*$
RewriteRule \/n\/([0-9]+)\/.*$ /novel.php?action=more&value=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/sn\/[0-9]+\/.*$
RewriteRule \/sn\/([0-9]+)\/.*$ /novel.php?action=all&type=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/[a-z][a-z]\/[0-9]+\/.*$
RewriteRule \/([a-z][a-z])\/([0-9]+)\/.*$ /category.php?action=product&product=$2&lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/[0-9]+\/.*$
RewriteRule \/([0-9]+)\/.*$ /category.php?action=product&product=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/img\/[0-9]+\/[0-9]+\/.*$
RewriteRule \/img\/([0-9]+)\/([0-9]+)\/.*$ /img.php?value=$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+[0-9]+\+.*$
RewriteRule /([0-9]+)\+([a-z][a-z])\+([0-9]+)\+.*$ /category.php?action=product&product=$1&lang=$2&something=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+.*$
RewriteRule /([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=product&product=$1&lang=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+\+.*$
RewriteRule /([0-9]+)\+\+.*$ /category.php?action=product&product=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^\/img\/[0-9]+\/[0-9]+\/.*$
RewriteRule \/img\/([0-9]+)\/([0-9]+)\/.*$ /img.php?value=$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+[0-9]+\+.*$
RewriteRule /([0-9]+)\+([a-z][a-z])\+([0-9]+)\+.*$ /category.php?action=product&product=$1&lang=$2&something=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+.*$
RewriteRule /([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=product&product=$1&lang=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+\+\+.*$
RewriteRule /([0-9]+)\+\+.*$ /category.php?action=product&product=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[0-9]+$
RewriteRule /([0-9]+)$ /category.php?action=product&product=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/s[0-9]+\+[a-z][a-z]\+.*$
RewriteRule /s([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=something&value=$1&lang=$2 [L]
</IfModule>
You can use these 2 rules in your root .htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^(?:d/)?(.+?)\.html?$ index.php?d=$1 [L,QSA,NC,R]
I have PHP file .htaccess :
Options -Multiviews
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?user=$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/home/.*$ index.php [QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/friends$ friends.php?user=$1 [L]
RewriteEngine On
RewriteRule ^post/(\d+)/([a-z-]+) post.php?id=$1&title=$2 [L]
Now I want the url post to be like this :
http://example.com/yoana/post/id_post
I tried with that rule above, but it is still not working.
The error is :
Object not found!
Any ideas?
I'm trying to remove .php from my url,
below is my .htaccess contents
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ path.php?username=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
I don't have any idea what's going wrong.
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
You need an additional rule to redirect .php URL to non-php one. Try this code:
Options -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ path.php?username=$1 [L,QSA]
RewriteCond %{THE_REQUEST} \s/+folder/(.+?)\.php[\s?] [NC]
RewriteRule ^ %1? [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]