I'm trying to get a my original url which would have been properties.php?bed=1&page=1&perpage=12&area=testarea to /search/1/1/12/testarea. But the last query string 'area' is optional and so could be blank.
I have this so far below, the problem is if I add an extra ([^/]+)/ such and
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/([^/]+)/? pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4
and then don't supply an area in the url, it fails to work correctly. Is there a correct way to do this where the query sting can be optional?
Also another problem I'm having is I would like this
RewriteRule search-rooms/([^/]+)/([^/]+)/([^/]+)/? pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4
to be /search/rooms/ not /search-rooms/ but if I put an extra / after search it again doesn't work correctly and the page reads the wrong data from the URL.
This is the full version
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule property/([^/]+)/? pages/show.php?id=$1 [NC,L]
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/? pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4 [L,QSA,NC]
RewriteRule search-rooms/([^/]+)/([^/]+)/([^/]+)/? pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4 [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^www.studentlettingsagency.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^studentlettingsagency.co.uk$
RewriteRule ^(.*) http://www.stla.co.uk/$1 [QSA,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Any help would be great!
You can use the following rule :
RewriteCond %{REQUEST_URI} !^/search/rooms
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$ pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4 [NC,L]
RewriteRule search/rooms/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$ pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4 [NC,L]
RewriteCond is important here ,as it tells the first rule not to match the uri /search/rooms
Related
I'm struggling with a problem trying to rewrite a url without changeing its content.
I want to display in browser url a different url, but the content still the same
My url is http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro
And i wanna change it to http://fortin.agency/audit-seo/578/leasingautomobile.ro
What i've done:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^frtcrwl/health_check/report/(.*)$ /$1 [L,NC,R=301,NE]
Doesnt work... Any help?
EDIT
578 in the url is dynamic, also the "leasingautomobile.ro"
EDIT #2
Final code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(audit-seo)/frtcrwl/health_check/report/(.+)$ [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
Still not working as expected yet as it throws error 404. Can the path remain unchanged? Coz the url in browser link now is perfect. Thanks to #anubhava till now
Change your rule to this and retest inside frtcrwl/.htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteBase /audit-seo/frtcrwl/
RewriteCond %{THE_REQUEST} \s/+(audit-seo/frtcrwl)/health_check/report/(\S+) [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]
RewriteRule ^\d+/[^/]+/?$ index.php?/health_check/report/$0 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L,QSA]
If you want to be abble to access http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro from http://fortin.agency/audit-seo/578/leasingautomobile.ro you can use the following rules:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^audit-seo/(.+)$ audit-seo/frtcrwl/health_check/report/$1 [L,NC]
I wanna to get rid of GET string parameters, from keys.
For example this is initial uri:
http://example.com/api/get_users_method?user_age_from=18&user_age_to=25&user_city=ohio
http://example.com/api/get_users_method?user_age_from=18&user_age_to=25
http://example.com/api/get_users_method?user_city=ohio
I wanna make like this:
http://example.com/api/get_users_method/18/25/ohio
http://example.com/api/get_users_method/18/25
http://example.com/api/get_users_method/ohio
How can i get this result? I found some solution, to edit htaccess file, but it doesn't work unfortunately, maybe i made some mistakes in htacces file? I'm using php. Thanks!
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /api/get_users_method?user_age_from=$1&user_age_to=$2&user_city=$3 [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /api/get_users_method?user_age_from=$1&user_age_to=$2&user_city=$3 [NC,L]
You have to treat the rules separately. All Conditions preceding rules only apply to a single rule. Following rules are not touched by that rule.
You will 3 separate rules in your root .htaccess (a level above api directory)
Options -MultiViews
RewriteEngine On
RewriteRule ^(api/get_users_method)/(\w+)/(\w+)/(\w+)/?$ $1?user_age_from=$2&user_age_to=$3&user_city=$4 [NC,L,QSA]
RewriteRule ^(api/get_users_method)/(\w+)/(\w+)/?$ $1?user_age_from=$2&user_age_to=$3 [NC,L,QSA]
RewriteRule ^(api/get_users_method)/(\w+)/?$ $1?user_city=$2 [NC,L,QSA]
I have dynamic URL website (irasol.com) while i navigate to menu the url shows like
http://irasol.com/index.php?id=1
I want url like this
domainname/home
domainname/aboutus
domainname/contactus
domainname/apply
home, aboutus, contactus, apply are menu name it is already in database.
my htaccess file is
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]*)\.php$ /index.php?id=$1 [L]
Use this instead:
Options -Multiviews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ index.php?id=$1 [B,L]
Explanation
The first three conditions make sure that domainname/aboutus is not a real file, so that we don't rewrite files that already exist.
Options -Multiviews removes a number of potential problems
In your current code, get rid of the .php in your pattern:
RewriteRule ^([^/]+)$ /index.php?id=$1 [L]
You are not matching .php extensions in the request. You are only routing matches to a query string on a real .php extension
As for a better solution:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?id=$1 [L]
I have this link:
index.php/forums/viewforum/5/
Now, I want that "forums" word in URL to become dynamic such that which ever word I replace it with, it still redirects to the same URL.
For example, if I have:
ProductA/viewforum/5/
it redirects to:
forums/viewforum/5/
For example, if I have:
ProductB/viewforum/13/
it redirects to:
forums/viewforum/13/
In other words, if there's a "view forum" word in the URL, it should trigger this rewrite.
I already have a .htaccess that removes the index.php from the URL so the rewrite rule should consider that too.
Is it possible?
HTACCESS:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule member http://%{HTTP_HOST}/404 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^[^/]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(images|favicon\.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.+)$ /index.php/$1? [L]
</IfModule>
Your 2nd and 3rd rules look suspect.
Have your full code like this:
RewriteEngine on
RewriteRule member http://%{HTTP_HOST}/404 [R=301,L]
RewriteCond %{REQUEST_URI} !^/forums/ [NC]
RewriteRule ^[^/]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(images|favicon\.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.+)$ /index.php/$1 [L]
I have big problem with my urls. I know how to remove index.php form url, but problem is that I don't know to remove that "?act=" from url.
My link now is http: //localhost/doctrine/public/?act=test and I want to create it like http: //localhost/doctrine/public/test.
My current .htaccess file placed in public folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need help how to do that.
Use this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /doctrine/
RewriteRule ^(public)/([^/]+)/?$ $1/?act=$2 [L,QSA,NC]
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Before your expression engine rule, you can add:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /doctrine/public/?act=$1 [L]
To internally rewrite a request like http: //localhost/doctrine/public/test to /doctrine/public/?act=test. You need to make sure the links in your content look like /doctrine/public/test instead of the one with the query string. If there are links outside of your control (like google indexed pages) you can add this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /doctrine/public/?\?act=([^&\ ]+)
Rewrite Rule ^ /doctrine/public/%1? [L,R=301]
to point browsers to the URL without the query string.
This unfortunately isn't going to be compatible with your expression engine URLs.