I managed to rewrite mydomain.com/file.php?id=## to this:
mydomain.com/##-Report_TITLE_OF_REPORT_HERE
by letting the .htaccess just take the ## and ignore anything that comes after it. I would like to change it to this:
mydomain.com/report-##/TITLE_OF_REPORT_HERE
However I cannot manage to wrap my head around it nor can I find any tutorial for this specific case online. The slash in the middle seems to muck everything up.
Could anyone tell me how to do this?
Try this:
RewriteRule ^report-(.*)/(.*)$ mydomain.com/file.php?id=$1 [L]
You can use this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^report-([^/]+)/ file.php?id=$1 [L,NC,QSA]
Related
I'm trying to rewrite my url, but I'm getting an error "500 Internal Server Error"
I've never done this before, and I've read some tutorials but I can't say I got any smarter from it.
The .htaccess file is in the root directory (/var/www)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /sub_domain/directory_to_my_files/
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*)/$ /index.php?pos=$1:$2&text=$3
The current link goes like this:
http://sub_domain.my_domain.com/directory_to_my_files/index.php?pos=(float|integer-only):(float|integer-only)&text=(any-text)
But I'm trying to do this:
http://sub_domain.my_domain.com/directory_to_my_files/(float|integer-only):(float|integer-only)/(any-text)/
Sorry if the links is a bit hard to read.
This should be placed in /directory_to_my_files/.htaccess
RewriteEngine On
RewriteBase /directory_to_my_files/
RewriteRule ^(-?[0-9.]+)[:-]([0-9.]+)/([^/]+)/?$ index.php?pos=$1:$2&text=$3 [L,QSA,NE]
I've tested this locally:
( I did not need the rewrite base )
RewriteEngine on
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*) /index.php?pos=$1:$2&text=$3 [R,L]
And it has redirected me
from
http://loc.domain/555-666/misc-text
to
http://loc.domain/index.php?pos=555:666&text=misc-text
I reckon this was what you wanted?
About the [R,L] at the end:
the R is telling apache to actually redirect, not just rewrite the url - this helps with testing.
the L is saying this is the last rule
Edit: could it be that the rewriteBase is causing you problems? Try it without and see if it works - at least you can nail where the problem is, then.
I want to change dynamic URL's to URL's more acceptable by search engines.
For example change this :
http://myurl.com.au/page.php?id=100&name=myname
to
http://myurl.com.au/100/myname.php
or .html at the end it does not matter.
I am using Apache 2.2. I am not using .htaccess rather I put my code in /etc/httpd/conf/vhosts/myfile
but it does not work, the URL does not change at all.
Options Indexes Includes +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.php$ /page.php?id=$1&name=$2 [L]
What am I doing wrong?
Either your have the wrong description in your question or your rule is backwards. Maybe this could work:
Options Indexes Includes +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} id=(.*)&name=(.*)$
RewriteRule ^/page\.php /%1/%2.php [L]
After doing some further testing it turns out that I do have the right code. I just don't have my head screwed on and was not thinking. Expecting that the mod_rewrite would magically change the URL to symbolic links when it is actually doing the reverse of that. It is all working for me now.
Url rewriting doesn't seem to work.
I want to rewrite http://www.domain.com/files.php?key=file&id=10 to file/10
So this is the code I wrote in my .htaccess file:
RewriteEngine On
ReWriteRule ^(.*?) files.php?key=$1&id=$2
Doesn't seem to work. Anyone having a idea why?
You need two groups to use $2. Try
RewriteEngine On
ReWriteRule ^([^/]+)/(\d+)/? files.php?key=$1&id=$2
[^/]+ Means one or more symbols each of them isn't slash
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z]+)/([0-9]+)/$ files.php?key=$1&id=$2
I have searched this forum and have done extensive google search and have not been able to figure it out. I have many links that look like:
mysite.com/example6.php?id=play-game
mysite.com/example6.php?id=watch-tv
mysite.com/example6.php?id=go-outside
I have tried lots of different code putting this in my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>
and many more attempts but nothing works to get my URLS to look like this:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
I do have mod_rewrite enabled on my server. Does anyone have any ideas?
Try this:
RewriteRule ^example6/(.*)$ example6.php?id=$1 [L]
Your first example (RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]) would correctly work for urls like "/play-game.html", and your second example (RewriteRule ^id/(.*) example6.php?id=$1) would correctly work for urls like "/id/play-game".
Prolly an easy one.. I am trying to study up on mod_rewrite and ran into an issue
Here is my url
example.com/index.php?id=1&title=some_title
I want the page to be able to take
example.com/1/some_title.html
How would I do that?
RewriteEngine on
RewriteRule ^(\d+)/(\w+).html$ index.php?id=$1&title=$2
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)\.html$ index.php?id=$1&title=$2