Hi everyone i need help about htaccess. I am trying to make a facebook style profile url like : https://www.example.com/azzo
So the user_profile.php is in the pages folder. Now user profile link is this http://www.example.com/pages/user_profile?username=azzo So i want to cut the pages file name from the url. What should i do to use my url like facebook (https://www.example.com/azzo) .
I am using the following htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^group/([\w-]+)/?$ pages/group.php?group_username=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]
What should i do to change the url like this:
http://www.example.com/pages/user_profile?username=azzo
to this
https://www.example.com/azzo
I have tryed the following rule:
RewriteRule (?:^|/)([\w-]+)/?$ pages/user_profile.php?username=$1 [L,QSA]
after the
RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]
but i get blank page.
Related
I am trying to add some other page for my project. But i have one question about php extension.
So i am using htaccess for some url like following htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteRule ^friends/([\w-]+)/?$ /friends.php?username=$1 [L,QSA]
RewriteRule ^followers/([\w-]+)/?$ /followers.php?username=$1 [L,QSA]
RewriteRule ^status/([\w-]+)/?$ /status.php?msgID=$1 [L,QSA]
RewriteRule ^following/([\w-]+)/?$ /following.php?username=$1 [L,QSA]
RewriteRule ^followers/([\w-]+)/?$ /followers.php?username=$1 [L,QSA]
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ /profile.php?username=$1 [L,QSA]
Now, i have created photos.php from the details folder and the link is :
Go Photos
When i click the Go Photos link i want to remove that url php extension like
http://www.name.com/details/photos
I have still tryed some answer from stackOverflow
Remove .php extension from url
Remove php extension from url
but that answers gives me 404 page not found.
How can i remove .php extension from url anyone can help me here ?
You need additional rules for removing .php extension.
Use these rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^status/([\w-]+)/?$ status.php?msgID=$1 [L,QSA]
RewriteRule ^(following|followers|friends)/([\w-]+)/?$ $1.php?username=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule (?:^|/)([\w-]+)/?$ profile.php?username=$1 [L,QSA]
i have problem to improve my htacces to contain more pages
, i have htacess that delete the parameter of Playlist.php?v=1 and convert it to Playlist/1
the real problem is i have more than Playlist page
i have 5 page more like Type.php,Videos.php,Watch.php
i tried to douple the same code in the htacces with different parameter but
nothing worked with me
my htacces code is
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /PlayList\.php\?v=([^\s&]+) [NC]
RewriteRule ^ /PlayList/%1? [R=302,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteRule ^PlayList/(\d+)/?$ PlayList.php?v=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Using regex alternation you will need only single rule rather than 4 rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /(PlayList|Type|Videos|Watch)\.php\?v=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteRule ^(PlayList|Type|Videos|Watch)/([^/]+)/?$ $1.php?v=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
I solved the question by changing the code completely
this is my so small solution
RewriteEngine On
RewriteRule ^PlayList/([^/]*)$ /PlayList.php?v=$1 [L]
RewriteRule ^Type/([^/]*)$ /Type.php?v=$1 [L]
RewriteRule ^Videos/([^/]*)$ /Videos.php?id=$1 [L]
RewriteRule ^Watch/([^/]*)$ /Watch.php?v=$1 [L]
My link is
search?c=category&s=product
I have already removed the .php with htaccess, everything is working apart from when a user searches, the first page will show the link above, I want to show the link as below:
search/category/product
I tried the below code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^product/(.*)/(.*)/(.*) product.php?id=$1&c=$2&name=$3
RewriteRule ^search/(.*)/(.*)/(.*) search.php?c=$1&s=$2&page=$3
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} \ /+search\?c=([^&\ ]+)&s=([^&]+)
RewriteRule ^ /search/%1/%2? [L,R]
What am I missing in the above?
Have rules this way:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /site/
RewriteCond %{THE_REQUEST} /search\?c=([^&\s]+)&s=([^&\s]+) [NC]
RewriteRule ^ search/%1/%2? [L,R]
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/?$ product.php?id=$1&c=$2&name=$3 [L,QSA]
RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2&page=$3 [L,QSA]
RewriteRule ^search/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
I have public html folder where some files and folders are stored. Then I have created a Folder In It. That Folder Contains Some Files And A Folder "Admin" which containes files related to my admin panel to surf my site members data.
Now I used Following Code In .htaccess file in public html folder which removes all pages's php extension.But When I try To Log In To My Admin Panel, Log In Fails.
e.g. www.abc.com >> Here .htaccess file Is with following code.
It works For Files in www.abc.com and for files in www.abc.com/xyz/index.php and other files. But When Tried www.abc.com/xyz/admin/index.php For Login, This Page just get refreshed But Doesn't allowing successful login.
Code used in .htaccess is as follows :
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
Try these rules that avoid redirecting for POST requests:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.(?:php|html)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]
My URL rewrite is working fine, the only thing is that after I click HOME to go back, the URL is showing mywebsite.com/test/index and I want get rid of the index to show only mywebsite.com/test/. This is my .htaccess:
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{THE_REQUEST} \s/+(rscares/.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
#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]
Any help? Thanks.
You can use this code:
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{THE_REQUEST} \s/+(rscares)/(?:index)?(.*?)\.html[\s?] [NC]
RewriteRule ^ /%1/%2 [R=301,L,NE]
#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]