I'm totally newbie in htaccess and it has been a month since I'm trying to rewrite this one URL but no luck. Tried searching on the internet a lot and tried out the method that worked for others but not working for me unfortunately.
The htaccess rule for my dynamic page works, for example site/index.php?viewpage=application shows up as site/application
What I'm struggling to do is, I'm trying to rewrite the following url: site/application?name=abcd&date1-2-3&version=5.0 to site/application/abcd/1-2-3/5.0
This is my htaccess code
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?viewpage=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /application?name=$1&date=$2&version=$3 [L]
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !name
RewriteRule ^([^/]+)$ index.php?viewpage=$1 [L]
RewriteRule ^(.+)/(.+)/(.+)/(.+)$ /$1?name=$2&date$3&version=$4 [L]
If you want the last line to be limited with application only , replace with this :
RewriteRule ^application/(.+)/(.+)/(.+)$ /application?name=$1&date$2&version=$3 [L]
UPDATE CODE:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !name
RewriteRule ^([^/]+)$ index.php?viewpage=$1 [L]
RewriteRule ^(.+)/(.+)/(.+)/(.+)$ index.php?viewpage=$1?name=$2&date$3&version=$4 [L,NE]
Related
Is it possible to using htaccess?
I want to keep my original url "menu", but also use /en/menu/ for it.
Here is my code so far (sorry I am terrible at htaccess):
RewriteEngine On
RewriteBase /server/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/menu/ [NC]
RewriteRule ^([^/]+)/([^/]+)en/menu/ [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /menu/ [L,QSA]
I have a web site working on localhost for now.
I send some data with get method to another controller
When I send data my url is look like:
http://localhost/book/Control/?kolon=&satir=unknown&modals=infox&bookid=4555
but i want to it look just like:
http://localhost/book/4555
I tried editing my .htaccess file like below but it does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L]
</IfModule>
how can I fix it?
You want the pretty URLs through htaccess.
The following is tested and works works:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^book/(\d+)*$ ./book/Control/?kolon=&satir=unknown&modals=infox&bookid=$1
Refer: https://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
Try to change it in that way:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
If bookid it's a numeric value you can use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([0-9]+)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
I would like to redirect link http://example.com/asdasdas/edit to http://example.com/asdasdas/index.php/edit using htaccess. I did this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} edit
RewriteRule ^ %{REQUEST_URI}/index.php [L,R=301]
but it's a loop and doesn't works well. Any ideas?
You can use this rule in /asdasdas/.htaccess:
RewriteEngine On
RewriteBase /asdasdas/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php/$ [L]
This will support URL of http://example.com/asdasdas/edit
I'm trying to block the ZmEu and Ezooms abuse I've been getting. I tried following what was discussed in this link: http://www.philriesch.com/articles/2010/07/getting-a-little-sick-of-zmeu/ but my attempt results in Error 310, too many redirects. Any idea what's causing this loop?
My htaccess code is below. I temporarily set one of the HTTP_USER_AGENT values as Chrome to test it.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/my_base/special/ip-flagged
RewriteCond %{HTTP_USER_AGENT} (.*)Chrome(.*)|(.*)ZmEu(.*)
RewriteRule .* /my_base/special/ip-flagged [R=301,L]
RewriteBase /my_base
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Thanks
I figured it out. Adding the lines,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
to the first RewriteRule stopped the loop. So now the following code always redirects to the "ip-flagged" page whenever the browser used is Chrome:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/my_base/special/ip-flagged
RewriteCond %{HTTP_USER_AGENT} (.*)Chrome(.*)
RewriteRule .* /my_base/special/ip-flagged [R=301,L]
RewriteBase /my_base
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
I am trying to redirect http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop using htaccess. However, It keeps redirecting here: http://test.pearlsquirrel.com/explore_all/?u=site_error.php. I have looked all over Stackoverflow for the answer but I just can't seem to find it. I would really appreciate some help in fixing this problem, thanks!
Here is my .htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} [^=]+=([^=]+)
RewriteRule .* /%1? [L]
Will map this:
http://test.pearlsquirrel.com/explore_all?u=hiphop
To this:
http://test.pearlsquirrel.com/explore_all/hiphop
Replace the corresponding code in your .htaccess file with this one.
I have not checked the rules in your .htaccess file.
OPTION
Now, if it is the other way around, which I think it is, and the idea is to map this incoming URL:
http://test.pearlsquirrel.com/explore_all/hiphop
To this resource:
http://test.pearlsquirrel.com/explore_all?u=hiphop
Replace the above rule set with this one:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L]