Creating friendly URLs with mod_rewrite in htaccess? - php

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".

Related

How to have a post variable defined without '?{name}=' in the url?

Currently on my website, my profile urls look like this:
../user/?id=1
I would rather them look like this:
../user/1
How would I go about this? I'm running this with Apache and PHP if that is important to the question.
You can do this with .htaccess
Example:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9_-]+)$ user.php?id=$1 [L,QSA]
</IfModule>
This htaccess rule will redirect input like www.site.com/user/123 to user.php?id=123

Htaccess rewrite working but without query string

I have a simple rewrite that works on localhost but not on my server. I'm trying to rewrite
www.website.com/arrangements/garden
to
www.website.com/arrangements.php?link=garden
and the code I have is
RewriteEngine On
RewriteRule ^arrangements/(.*)/?$ arrangements.php?link=$1 [NC,L]
But what I get on the server is only arrangements.php. The query string link is not present. I've tried everything I could think of and contacted hosting support as well, they got nothing.
Any ideas?
Use this,
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^arrangements/(.*) arrangements.php?link=$1 [L]

Hide a part of a URL with mod_rewrite but keep the argument

I would like to write a rule where the members/show/ string will be hidden in the URL.
The original URL: localhost:8080/sandbox/member/show/helloworld, where helloworld is the name of the account. I'd like it to be localhost:8080/sandbox/m/helloworld. Basically, the content delivered will be from the full url, but I'd like it to be hidden for any user.
RewriteRule ^.*$ member/show/$0 [L,QSA] doesn't seem to work, it throws a 500 Internal Server Error. I work with the CodeIgniter Framework, and the following rewrite rule is already present: RewriteRule .* index.php/$0 [PT,L].
I tried several RewriteRule options but without success. I'd be very glad if anyone could shed some light related to my question.
Best regards.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sandbox)/m/([^/]+)/?$ /$1/member/show/$2 [L,NC]

Rewriting urls with mod_rewrite - GET variables

I found out I could make clean urls with mod_rewrite. I managed to make pages like /home.php viewable by visiting /home (without .php).
Now, I'd like to turn view_album.php?album_id=23 into album/23
This is the code I use, but sadly it's not working:
Options SymLinksIfOwnerMatch MultiViews
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/(.*)/ view_album.php?album_id=$1
Thanks in advance.
use
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/([0-9]*)$ view_album.php?album_id=$1
and make sure you only rewrite if a noting or a number follows album/, so your can access your images, which may be in a folder named album.

htaccess mod rewrite slash issue

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]

Categories