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?
Related
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]
I have PHP .htaccess to manage user profile like this :
http://example.com/user?=blabla
to be
http://example.com/blabla
Here is the .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
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?user=$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/home/.*$ index.php [QSA]
Now I want to make like this :
http://example.com/blabla/post/
post is a folder.
I tried make folder post in root folder but still wrong. But when I tried to type this URL, http://example.com/user/post it running OK.
What I want is user can open http://example.com/blabla/post/
You can use this rule:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.+?)/?$ $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ user.php?user=$1 [L,QSA]
I am trying to rewrite this url:
news?post=title
to
news/title
This is what i have been trying
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^/]*)\.$ /news?post=$1 [L]
try
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/([a-z]+)?$ news?post=$1 [L,QSA]
My URL : http://example.com/index.php?L=F/12345678
This is what i tried.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/?$ index.php?L=$1 [QSA,L]
This is what i expect: http://example.com/F/12345678 but dosent work.
This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?L=(.*)\ HTTP
RewriteRule ^ /%2\? [R,L]
#Internal rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?L=$1 [L]
It should change http://example.com/index.php?L=F/12345678 to http://example.com/F/12345678
Try using:
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?L=$1 [L]
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]