Ok, im pretty new at this and I would really appreciate some help, thanks!
How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/?url=contact
All i want to do is remove the query string
/contact
Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all
This was my solution:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]
To a user on your site, they will see and navigate to this:
http://example.com/contact
But the real page would be something like this:
http://example.com/index.php?url=contact
This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html %1
(or whatever if it's not index.html, index.php, whatever)
You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule
Before: https://example.com/index.php?user=robert
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
After: https://example.com/user/robert
Related
Pretty straightforward - just wondering how do I rewrite this:
/folder/subfolder/file
/?f=folder/subfolder/file
And the number of folders/subfolders might vary, so what I really want is anything after the / in that path (that does not already have ?f= in it) redirected to the path with ?f= added in front of it.
If I add this
RewriteRule ^(.*)$ ?f=$1 [L]
it works just fine but doesn't recognize the existence of ?f= in the URL already, and breaks that existing link with ?f= in there.
Any ideas?
You can use:
RewriteCond %{QUERY_STRING} !(?:^|&)f= [NC]
RewriteRule ^(.*)$ ?f=$1 [L,QSA]
Which does not do the rewriting if the f querystring is already there.
With [QSA] you keep the other possible querystring values.
Try this :
RewriteEngine On
RewriteRule ^(.[^\?]*)$ /?f=$1 [L]
I have this url
http://example.com/profile.php?u=78
I wanted to changed it to be like this
http://example.com/78/
How would I do that?
Please Help
Thanks in advance
You can use this .htaccess in your root directory:
RewriteEngine on
RewriteRule ^(\d+)/?$ /profile.php?u=$1 [L]
RewriteCond %{QUERY_STRING} ^u=(\d+)$
RewriteRule ^profile.php$ /%1/? [R=302,L]
Change [R=302,L] to [R=301,L] when that work well
Try this to rewrite http://example.com/profile.php?u=78 into http://example.com/78/:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^profile.php$ /%2/
RewriteRule (.*) $1? [R=permanent]
Line-by-line explanation:
Turn on rewriting functionality
Specify the condition to make sure the query string is in the form of foo=bar for the following rules to apply.
Rewrite profile.php?foo=bar into /bar/?foo=bar
Remove all query strings that may still be appended to the new URL like /bar/?foo=bar/. This rule essentially substitute the entire path (.*) with itself ($1), and emptying the query string (?). [R=permanent] performs a permanent redirect (301).
Also, as previously commented, please ensure that http://example.com/78/ is a valid URL.
my friends.
Please, I have an issue with ReWriteCond. I would like to create friendly search results. I just do it with ReWriteRule, but I would like to do the reverse path.
This is working pretty good:
RewriteRule ^search/([^/]*)$ /index.php?p=search&query=$1 [L]
But I would like to convert /index.php?p=search&query=$1 into search/query
Thanks.
Do redirect from "ugly" search form GET request to nice URL like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=search&query=(.*)$
RewriteRule ^index\.php$ /search/%1? [R=301,L]
Then you have to make sure, the "nice" URL will reach your script like this:
RewriteRule ^search/(.*)$ index.php?query=%1&p=search [L]
Notice the different order of arguments / it prevents infinite loop
I want to make a RewriteRule rule so when someone goes to the base index of my site eg:
example.com/
I want this to happen:
RewriteBase /
RewriteRule ^/ /index.php?pageID=1
So when someone goes to the homepage; a query for pageID=1 is sent.
However the above code doesn't work, going to the homepage with the above code doesn't get the query sent. (other rewrite rules are working correctly)
Any help would be appreciated. Thanks.
Remember RewriteRule has no / at the beginning of it!
RewriteRule ^$ index.php?pageID=1
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*)$ /index.php?pageID=1
i want to use somthing like http://www.example.com/domain.com instead of http://www.example.com/index.php?url=domain.com.
how can I do this using .htaccess?
update: i finally figured it out. :)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1
http://www.pagerankcheckertool.com/facebook.com
RewriteEngine on
RewriteRule ^(.+)$ index.php?url=$1
Depending on your needs, it may not be such a good idea to have everything rewritten as per your example, e.g. even a www.example.com/index.html would be rewritten to www.example.com/index.php?url=index.html so i'd recommend you use an initial sub folder or something in the url to seperate your rewritten urls from anything else.. i.e. www.example.com/urls/domain.com
To accomplish that you could setup a rewrite rule.. (assuming you have mod_rewrite active)
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^urls/(.+) /index.php?url=$1 [NC]
that basically means any url that begins with urls/ and has one or more characters following.. the brackets around the .+ will 'group' that element and allow you use it again with the $1
Hope that solves what you want to accomplish!