i would like to rewrite all my website's urls from this
https://website.com/page.php?lang=2 to this
https://website.com/en/page
(creating /en/ directory while hiding .php extension)
Can anyone help me with this one?
Thank you in advance
Try it like this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/([\w-]+)$ $1.php?lang=2 [QSA,L]
Related
I am passing a name which will be used as the subfolder but the filename remains the same eg foldername/gallery.php?q=new_folder should be new_folder/gallery.php using htaccess.
Attaching the htaccess of what I a trying to do
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(gallery.php)$ $2.php?q=$1 [L]
gallery.php is the filename and $1 is basically the new_folder. Been struggling with this for quite a bit.
You are fairly close. You just need to use foldername/ in target URI of your rule.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(gallery\.php)$ foldername/$2.php?q=$1 [L,QSA,NC]
I have just added bellow mentioned code in .htaccess. Hope this will help you.
RewriteEngine On
RewriteRule ^foldername/(.*) http://example.com/newfolder/gallery.php?options=$1 [R=301,L]
I made an URL Shortener and shortened links looks like this:
http://patison.eu/06uoM. My PHP code checks if this 06uoM is in my database - if yes it will redirect to the correct page, if not it will open index.php file from index_html directory. It's bad because when I write URL to image uploaded on server it will open index.php because URL is not in database...
http://patison.eu/forum/images/off.gif - see?
This is how .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
Please help me solve this problem!
It sounds like you want to let 404 errors happen on URLs like
http://patison.eu/forum/images/off.gif
but not on URLs like
http://patison.eu/06uoM
If that is the case, you can change your .htaccess code to this to limit the type of URLs rewritten:
RewriteEngine on
# Limit rewrites to urls like '/06uoM' or '/06uoM/', but not like '/forum/images/off.gif'
RewriteCond %{REQUEST_URI} ^/[0-9a-z]{5}/?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
I have the following code on my htaccess:
RewriteEngine On
RewriteRule ^course-details/([a-zA-Z0-9]+)/$ course-details.php?id=$1
I think this gave me a URL like this: /cp/course-details/5 where 5 is the id of the course.
But when I go to this address I get 404 not found. Also, our current url is
/cp/course-details.php?course-details.php?name=bla-bla-bla&category_id=1
and we need a friendly url like this
cp/category-name/course-name/
Thanks in advance for you help.
You can try this in your htaccess file if the php file is in the cp dir. Since it appears your are developing in a subfolder(peppers) of your dev box you can try this.
RewriteEngine On
RewriteBase /peppers/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
If this is for production then you can use this in the .htaccess file in the root.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ /cp/course-details.php?name=$1 [NC,L]
RewriteRule ^course-details/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/.*$ course-details.php?id=$1&category_id=$2
With that, you can use URL like course-details/1/5/category-name/course-name
Because URL allow: course-details/category_id/id/what-ever-you-want
How do I use .htaccess to rewrite:
mysite.com/profile/[username]
go to:
mysite.com/profile.php?id=[username]
I don't want to have to reload the page just change the URL to make it look good.
Any help is appreciated.
This is the htaccess rule that should get you started:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule profile/(.+) profile.php?id=$1
I need some help figuring out how to write this .htaccess.
My file is in mywebsite/part5/thanksfordownload.html. How to use .htaccess to have url mywebsite/thankyoufordownload.html?
I tried using this for the .htaccess but no dice. I tried uploading it both in the root and in the folder itself.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /part5/$1 [L]
Not sure what went wrong in this part,
thanks for your views & comments in advance!
Ok so basically if you only want that rule - you'd want to do something like this -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^thankyoufordownload.html$ /part5/thankyoufordownload.html [L]
Simply:
RewriteRule ^thankyoufordownload.html$ part5/thanksfordownload.html
This will only work for the example asked about.