I have a file called filename-step1.php and looking to make the url domain.com/filename/step1 through .htaccess.
My current .htaccess file looks like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
At the moment, this works fine for removing the .php tag from the url. Just need to fix the directories.
You could add a RewriteRule to redirect to $1/$2.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /$1-$2.php [NC,L]
</IfModule>
So, filename/step1 will trigger the filename-step1.php file.
I am giving 2 solutions here, please try one at a time only in your .htaccess file. With your shown samples, could you please try following as a Generic rules.
RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ $1-$2.php [NC,L]
OR in case you are looking for specifically url filename/step1 try following.
RewriteEngine ON
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteRule ^(filename)/(step1)/?$ $1-$2.php [NC,L]
Related
can you please let me know htaccess code to redirect there urls:
https://www.example.com/forum/news/state-news/archive to https://www.example.com/forum/news/state-news?archive=yes
https://www.example.com/forum/news/state-news/city-news/archive to https://www.example.com/forum/news/state-news/city-news?archive=yes
https://www.example.com/forum/news/state-news/city-news/area-news/archive to https://www.example.com/forum/news/state-news/city-news/area-news/?archive=yes
My tried htaccess file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(core/libraries/|includes|core/includes|core/vb|core/vb5|core/admincp|core/modcp) index.php?routestring=relay/404 [END]
RewriteRule ^css.php$ core/css.php [NC,L]
RewriteRule ^install/ core/install/ [NC,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?routestring=$1 [L,QSA]
</IfModule>
Have your htaccess Rules file in following way. I have specifically covered 3 URLs shown by you in your question. Please make sure you use these Rules and make sure you clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(core/libraries/|includes|core/includes|core/vb|core/vb5|core/admincp|core/modcp) index.php?routestring=relay/404 [END]
RewriteRule ^css\.php$ core/css.php [NC,L]
####I have commented below rule that doesn't make sense, since NO right part in it only condition is mentioned.
####RewriteRule ^install/core/install/ [NC,L]
###New rules added by me to handle 3 different URLs shown by OP in question.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(forum/news/state-news(?:(?:/city-news(?:area-news))))/(archive)/?$ $1?$2=yes [NC,QSA,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?routestring=$1 [L,QSA]
</IfModule>
I am on apache 2 and I would know if my htacces is correct
my url are for example :
localhost/test/boutique/index.php
localhost/test/boutique/index.php/language,en
localhost/test/boutique/index.php/Products/Description/products_id,1
localhost/test/boutique/index.php/Products/Description/products_id,2/language,fr
What is the best approach for a good url like above
In suppose index.php must deseapear to hav someting like that
localhost/test/boutique/Products/Description/products_id,1
I try this but it does'nt work
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://localhost/test/boutique/index.php/$1 [PT,L]
Assuming /test/boutique/ is a real directory, you can use these rules inside /test/boutique/.htaccess:
RewriteEngine On
RewriteBase /test/boutique/
# remove index.php if entered directly by clients
RewriteCond %{THE_REQUEST} /index\.php/(\S*)\s [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index\.php$).* index.php/$0 [L,NC]
I have never edited the .htaccess file before so sorry for my awful attempt
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ http://example.site/index/%1 [R=302,L]
I am tryting to rewrite http://ex.com/shop/?s=sa to look like http://ex.com/shop/sa
I am assuming you are using rewriterules in shop directory and index.php is handling the data then try with below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ index.php?s=$1 [L]
I need your help I am trying to change my URL format but I cannot do that I keep getting Object Not Found error.
Real URL is : http://localhost/website/page.php?pid=about
I want like this url using htaccess http://localhost/website/about.php
My code is:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([a-zA-z0-9\_\-\+]+))\.html|([a-zA-z0-9\_\-]+)\.php$ page.php?pptype=$2&pppage=$3&id=$4 [QSA,NC,L]
</IfModule>
Try it like this for your url similar to http://localhost/website/about.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewrwiteRule ^([\w-]+)/([\w-]+).php$ $1/page.php?pid=$2 [L]
Use this in your .htaccess:
RewriteEngine On
RewriteRule ^website/([^/]*)\.php$ /website/page.php?pid=$1 [L]
It will leave you with the URL: http://localhost/website/about.php
I have a yii app that has separate back end and front end. I am trying to make friendly url.
I have tried some online tools but could not get it correct
So I want this url
http://mydomain.lc/abs/admin/some/crazy/urls (for example
some/crazy/urls can be admin/index)
will be rewritten to:
http://mydomain.lc/abs/backend.php/some/crazy/urls (because this
url works directly)
And I have also front end site but they are both in the same project so they share .httacess.
the rule for .htaccess for front end is:
this url:
http://mydomain.lc/abs/some/crazy/urls (some can not be admin
here, so we can differentiate btw fron and back end)
should be
http://mydomain.lc/abs/index.php/some/crazy/urls
I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^abs/admin/?(.*?)$ abs/backend.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!abs/admin\/)(.*?)$ abs/index.php?url=$1 [QSA,L]
</IfModule>
the above script is not working.
Root is under abs folder and .htaccess in the root
You do not have to change anything except RewriteBase / to RewriteBase /abs
RewriteEngine On
RewriteBase /abs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/?(.*?)$ backend.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!admin\/)(.*?)$ index.php?url=$1 [QSA,L]
I guess the problem is with the RewriteBase.
You may try this in the .htaccess file in /abs directory:
Update according to last OP comment: this one is correct: backend.php/some/crazy/urls
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /abs
# Backend admin
RewriteCond %{REQUEST_URI} !backend\.php [NC]
RewriteRule ^admin(.*) /backend.php/$1 [QSA,L,NC]
# Frontend
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteCond %{REQUEST_URI} !admin [NC]
RewriteRule ^(.*) /index.php/$1 [QSA,L,NC]