I write the right subject but the site don't accept it - .htaccess

How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/index.php?page=pageCount&subject=mySubject
I want to change it to:
/index/pageCount/mySubject
and also
/show.php?subject=mySubject
to
/mySubject
and also
search.php?key=myKey
to
/key/myKey
thanks

In your .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index/([^/]+)/([^/]+)$ index.php?page=$1&subject=$2 [L,QSA]
RewriteRule ^key/([^/]+)$ search.php?key=$1 [L,QSA]
RewriteRule ^([^/]+)$ show.php?subject=$1 [L,QSA]

Related

.htaccess GET query string not work

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]

how to make friendly url using htaccess

I have been trying to force remove some unnecessary part of my url for example remove index.php? from this url.
/index.php?task=boost,boosting&action=index
The following rules apply not helped
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
how should look like the correct rule to hide unnecessary parts such as index.php or task or action?
With below rule you can use url yourdomain.com/boost/index you have to still pass value to task & action in some form so you cannot hide all the string from url until it is a post request.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)$ index.php?task=$1&action=$2 [QSA,NC,L]
Description You may use the following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

htaccess not rewriting correctly

I have this ReWrite rule in my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/]+)/?$ /index.php?id=$1 [L,QSA]
and when i go to:
domain.com/reports/helpdesk/tickets_report
it shows page not found, other pages seem to work fine
in this line of the htaccess, i needed to add a _
So, change:
RewriteRule ^([a-zA-Z0-9-/]+)/?$ /index.php?id=$1 [L,QSA]
to be:
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ /index.php?id=$1 [L,QSA]

decide page based on number of parameters - htaccess url rewrite

i am writing RewriteRule(s) on htaccess which decides which page it redirect to based on the number of parameters.
for example, "http://mysite.com/tommy"
this will redirect to "mysite.com/user.php?user=tommy"
whereas, "http://mysite.com/tommy/pets"
will redirect to "mysite.com/show.php?user=tommy&category=pets"
note, the first URL has only one parameters and it redirects to user.php and second URL has two parameters and it redirects to show.php instead.
please help, and thanks in advance!
Currently...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)/?(.*)$ category.php?userId=$1&category=$2 [QSA,L]
RewriteRule ^(.*)$ user.php?userId=$1 [QSA,L]
</IfModule>
Done, for anyone else who need this too...
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ category.php?userId=$1&category=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ category.php?userId=$1&category=$2 [L]

404 page not found in YAMS

I would like some help here. I am using MODx with YAMS module which is for multilingual. I follow the installation and setup document from YAMS but I still get 404 page not found.
I would like to get:
localhost/sub/en/index.php?id=1
localhost/sub/fr/index.php?id=1
localhost/sub/th/index.php?id=1
the original link is
localhost/sub/index.php?id=1
here is rewrite rule in htaccess file. I got the rewrite rule from YAMS in "Server Config" tab.
# Friendly URLs
RewriteEngine On
RewriteBase /sub/
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# Redirect from mydomain.com/rootname to mydomain.com/rootname/
RewriteRule ^en$ en/ [R=301,L]
RewriteRule ^fr$ fr/ [R=301,L]
RewriteRule ^th$ th/ [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^th/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I am trying to search all the solutions everywhere. still no luck. please suggest or point me what i do wrong?
Thanks in advance
If you are getting links like localhost/en/index.php?id=1 in the frontend You have to fill the "MODx Subdirectory" field with "sub". You will find it in Modules->Yams->Other Params
Actually the problem is .htaccess file. I copys all .htaccess from YAMS and replaces the whole original .htaccess file. To solve my problem, I copy only friendly URL part and replace only this part in original .htaccess file.
here what I copy from YAMS and replace in my .htaccess file:
# Redirect from mydomain.com/rootname to mydomain.com/rootname/
RewriteRule ^en$ en/ [R=301,L]
RewriteRule ^fr$ fr/ [R=301,L]
RewriteRule ^th$ th/ [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^th/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Many thanks for suggestions.

Resources