.htaccess GET query string not work - .htaccess

I try to redirect url from
http://localhost/manual/$
to
http://localhost/manual/index.php?type=post&post=$
My file .htaccess is
RewriteEngine On
RewriteBase /manual/
RewriteCond %{REQUEST_FILENAME} !-f # Existing File
RewriteCond %{REQUEST_FILENAME} !-d # Existing Directory
RewriteRule . /manual/index.php? [L]
RewriteRule ^([^/]*)\/$ type=post&post=$1 [L]
But nor working whats wrong, help, sorry if duplicate because I still not understand to create htaccess.

You can use the following rule in /manual/.htaccess :
RewriteEngine on
RewriteBase /manual/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?type=post&post=$1 [L]

Related

htaccess rule for pretty URLs

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]

Struggling to rewrite the URL using htaccess

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]

htaccess displays error 500 when adding more than 3 rules

this is my htaccess:
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home index.php
RewriteRule ^register register.php
RewriteRule ^rules rules.php [L]
When i add fourth rule to htaccess it returns 500 error.
so htaccess is allowing only 3 rewrite rules?
First thing is when you receive an error you should always check your Apache error_log file. It will give you the specific reason for the error. We would only be guessing at what your problem might be.
Now this might not be "the" issue however the RewriteCond only works for the RewriteRule directly following it. You can't use the same condtions for all of your rules. You should also get in to the habit of using the [L] flag on the rules to prevent it from reading the next rule once it has matched.
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^register/?$ register.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^rules/?$ rules.php [L]

Htaccess redirect all to index.php not working if param starts http:// or www

I’m using that .htaccess to redirect all after slash to my index.php param :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
But then im trying to go mysite.co/http://someurl.co or mysite.co/http://www.someurl.co (mysite.co/www.someurl.co redirecting well) im getting error
You don't have permission to access mysite.co/http://www.someurl.co on
this server.
mod_rewrite engine strips all double slashes to single ones in RewriteRule so you cannot match http://www in RewriteRule. Use RewriteCond instead with THE_REQUEST parameter.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(\S+)
RewriteRule ^ /index.php?q=%1 [L,QSA]
Your code is unclear. What are you trying to do? This is the standard WordPress .htaccess which appears close to what you are attempting. Perhaps using that would work better:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteRule ^http\:\/+.*$ index.php?q=$0 [L,QSA]

.htaccess single variable url rewrite

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]

Resources