I have been working on an .htaccess file. The url I started with was, www.example.com/index.php?page=pagetitle. I want the Link to only show www.example.com/pagetitle.
So far the only thing in my .htaccess file removes the index.php.
Options -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.(php|html?)
RewriteRule ^ /%1 [R=301,L]
Any help would be greatly appreciated, I sadly don't have the knowledge to create these codes on my own.
Thank you in advance.
I will also be editing this question as I figure more of this out, from support of other people etc.
You can try these rules:
Options -MultiViews
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]
Related
Hello I have a main domain that have instabuilder setup on and when creating a page with instabuilding it creates it as "maindomain.com/pagename"
The problem I'm having is with my addon domain when I create a page with instabuilder it creates the link as addondomain.com/index.php/pagename Why is the index.php coming up, the link doesn't look nice.
Any help would be much appreciated. Thank you
This is the code you can use in your .htaccess (under DOCUMENT_ROOT) to remove index.php from URI:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
copy from
Remove 'index.php' from URL with .htaccess
I want to redirect my site to friendly.
I have my website pull data from database and adress is /post?id=1
and i want to change it to /post/1
I already wrote the code for rewrite but i cant make sense from google research how to redirect to /post/1.
my code
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L]
Use:
Options +FollowSymLinks
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+post\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /post/%1? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L,QSA,NC]
This one worked for me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ post.php?id=$1 [NC]
if you goto url /post/check1/
the htaccess file internally call post?id=check1
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /domain.com/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ /domain.com/$1.php [L]
am using this code for remove question mark but its not working, trying http://domain.com/details?id=71 to http://domain.com/details/id/71
Please help me where am wrong?
Thanks in advance
I'm not sure what you're trying to accomplish with the first rewrite, but for the second (the last three lines), if the incoming URI is not an actual directory or file, you want to rewrite something like details/id/71 to /details.php?id=71?
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?$2=$3 [L]
should get you close, assuming there are always 3 fields. In a RewriteRule you don't put the domain name again.
Your code doesn't do anything remotely close to what you want. Your code simply removes the php extension when a request is made explicitly with the extension and adds it back internally. In order to make http://domain.com/details?id=71 get redirected to http://domain.com/details/id/71, you need:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s/+([^/]+?)(?:\.php|)\?([^=]+)=([^&\ ]+)
RewriteRule ^ /%1/%2/%3? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1?$2=$3 [L]
you want this before your rules that remove the php extension
Assuming your script is called details.php, the following single rule:
RewriteRule details/(.*)/(.*)/$ /details.php?$1=$2
Should rewrite www.domain.com/details/id/71 to www.domain.com/details.php?id=71
You don't need all that other stuff to remove the .php extension.
I am creating a form at poll.php?code=STRINGHERE
I want to rewrite it with .htaccess to do WEBSITE.com/STRINGHERE
I have done it before but don't remember what I need to do in the .htaccess its something like
RewriteEngine On
RewiteRule ^(\w.+)$ ./poll.php?code=$1
Although I might be wrong. Any help would be great.
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewiteRule ^([^/]+)$ ./poll.php?code=$1 [L,QSA]
And if you need to redirect the browser when requests are made directly to poll.php:
RewriteCond %{THE_REQUEST} \ /+poll\.php\?code=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
I have tried many of the query to / answers from google and stack overflow, but can't find one that works for me.
I have a file users.php, and when I send users.php?user=username, I want that to be users/user/username. I already have the php extension removed in my .htaccess.
What's the best way to do this? Also, help with the proper file structure required would be helpful.
Edit: Here's what I have so far:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# to make `/path/index.php` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.php [NC]
RewriteRule . %1 [NE,R=301,L]
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]
RewriteEngine On
RewriteRule ^users/user/$ users.php?user=$1 [NC,L]
Try this htaccess code
RewriteEngine On
RewriteRule ^users/user/(.*)/$ users.php?user=$1 [L]
Hehe.. We all have the same answers! Try to remove all the code in your .htaccess file and then check this alone, just itself:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^users/user/([a-z0-9-_]+) /users.php?user=$1 [NC]
Use [NC] flag at the very end of the rule to be matched it in a case-insensitive manner. It means, the rule will doesn't care whether letters appear as upper-case or lower-case.
Now if the folder that containing your /users.php is entitled with /html, give this a try:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^users/user/([a-z0-9-_]+) /html/users.php?user=$1 [NC]
Just change the "html" as the name of the folder containing your users.php.
Okay, lets check this rule:
RewriteRule ^users/user/([a-z0-9-_]+) /beta/users.php?user=$1 [NC]
But please always don't forget the RewriteEngine on and to comment what's happening. And the URL that you must be checked is the not existed URLs that we're trying to remap. (Example: domain.com/users/user/name without a slash in the end.)