Really simple request. I want my url to look like:
http://localhost/movie/72105
instead of this
http://localhost/movie?id=72105
I currently have this setup going on in my .htaccess file, but it does not seem to be working:
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z\-]+)$ index.php?id=$1 [L]
</IfModule>
Just to clarify aswell, when the mod_rewrite is working successfully, I can still use to retrieve the ID?:
$_GET['id']
Much appreciated for any help.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^lab/movie/(\d+)$ index.php?id=$1 [L]
</IfModule>
Now, you can browse http://domain.com/movie/12 and $_GET['id'] will be 12.
I am using this one
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
RewriteBase /
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
you can retrive the id and other parameters (mobvie) by parsing
$_SERVER['REQUEST_URI']
in your index.php than.
also see: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Related
I am trying to shorten my website url of a newly added page event like
mysite.com/asoebi/myevent instead of mysite.com/asoebi/index.php?event=myevent
but every time i try to change my .htaccess file it give an error
here is .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^index/(\w+)$ ./index.php?event=$1
</IfModule>
You have to enable mod_rewrite in apache for this to work.
Put this one in the .htaccess file in the /public_html/asoebi/ folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /asoebi/
RewriteRule ^(.*)$ index.php?event=$1 [L]
</IfModule>
Also remove the last rewriterule from the main htaccess file you posted above
I'm new in PHP so I faced some problem using URL redirect using .htacess.
My URL page look like this: http://domain.com/blog_detail.php?id=blog_title
But I want change URL using .htaceess like this: http://domain.com/blog/blog_title
I have tried this, but it's not working:
<IfModule mod_rewrite.c>
RewriteEngine on # Turn on the rewriting engine
RewriteRule ^blog/([a-zA-Z0-9_-]+)$ blog_detail.php?id=$1
</IfModule>
I would use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f ## respect real files
RewriteCond %{REQUEST_FILENAME} !-d ## respect real directories
RewriteBase /
RewriteRule ^blog/(.*)$ blog_detail.php?id=$1&%{QUERY_STRING} [L]
&%{QUERY_STRING} only if you want to pass other variables here and there like:
http://domain.com/blog/blog_title?lang=fr
for instance
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>
I have a page in the following location: /property/happy_property_urls.php
My goal is to make the happy looking url's look like this: /en/london/apartment/for-rent/ww123/
I have tried various methods but none of them seem to stick and I only get 404 errors.
EXAMPLE NOT WORKING
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /property/
RewriteRule ^(.*?)$ happy_property_urls.php?lang=$1&city=$2&type=$3&status=$4&ref=$5 [NC,L,QSA]
</IfModule>
I am sadly failing badly.
Can someone give me some pointers please?
You can use this rule in the .htaccess in the root.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ property/happy_property_urls.php?lang=$1&city=$2&type=$3&status=$4&ref=$5 [NC,L,QSA]
</IfModule>
I made an simple framework for my website development.
I am currently using the this URL pattern:
www.example.com?r=account/login
But I would like to change it to:
www.example.com/account/login
remove r= from the URL.
I have seen YII framework does this. But I couldn't find a way to do this.
Solution:
Add the code below to your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?r=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ index.php?r=$1
</IfModule>`
What you are looking for are SEO friendly URLs which are quite common to use & implement. This is the .htaccess from a basic WordPress install which achieves a similar goal:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Then in index.php you can test this by doing a variable dump of $_GET like so:
echo '<pre>';
print_r($_GET);
echo '</pre>';
I see you found a solution however you don't/shouldn't need two rewrite rules for the same thing just to add the /. You can use a ? to make it optional. I also recommend using [L] on the rewrites so that it stops when the rule is met.
This is more of what you were looking for.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?r=$1 [L]
</IfModule>
I want to convert my link like this:
from http://example.com/pictures.php?title=new
to
http://example.com/new.
Here is my .htaccess; it's giving me a 500 internal server error.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]
</IfModule>
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
What's wrong in it?
I suspect your rewrite may be causing a loop. A RewriteCond to avoid a loop is usually a good idea;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/pictures.php
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]
You should avoid rewrtiing actual files like .js, .css and images to pictures.php. Try this rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /pictures.php?title=$1 [L,QSA]
you can try like this simply
RewriteEngine On
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]