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>
Related
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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^read(.+)?$ /read.php?id=$1 [QSA,L]
RewriteRule ^chapter(.+)?$ /readchapter.php?id=$1 [QSA,L]
RewriteRule ^list(.+)?$ /list.php?id=$1 [QSA,L]
</IfModule>
Above is my htaccess file, I trying create a story reading website.
I trying to shorten example link of
http://read.mydomain.com/chapter/three_little_fox/
So when it query
/chapter/three_little_fox
It will actually load readchapter.php?id=three_little_fox
But when I try load the page
http://read.mydomain.com/chapter/three_little_fox/
It throws a Internal 500 error.
Thanks for helping
The current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^chapter/([^/]*)$ readchapter.php?id=$1 [L]
</IfModule>
But the 404 error exist, my folder is this way
.htaccess
readchapter.php
index.php
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^chapter/(.*)/?$ /readchapter.php?id=$1 [QSA,NC,L]
</IfModule>
RewriteCond (Rewrite Conditions) ensures that if the request is already for a file or directory, RewriteRule will be skipped.
This will work for you:
RewriteEngine On
RewriteRule ^chapter/([^/]*)$ /readchapter.php?id=$1 [L]
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>
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
We’re using wordpress, and we have the following in the .htaccess:
# 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
We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and we want to rewrite it so that it becomes something like http://subdomain.example.com/fuel-card/
What do I need to add to the htaccess to do this? Also, will this affect the queries from running that uses GET variables?
nothing, just read the wordpress manual and edit your settings. checkout http://codex.wordpress.org/Using_Permalinks
--- EDIT
This can be done, but only if you have some sort of a standard markup of the url's you want to have rewritten. Ie. if you only want to rewrite the select-a-card url's, or only the url's with a syntax like http://site.com/uri/?q=something. But you if the syntax of the url's differ too much you will have to add a lot of rewrites.
In this specific case something like this should work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# add your specifics below:
RewriteRule ^/select-a-card/\?q=(.*) $1-card/
RewriteRule . /index.php [L]
</IfModule>