I am attempting to have my GET parameters display in the url as a directory. So, mywebsite/?pix=5 would show as mywebsite/5. There are only numbers I have to look up. I have the following .htaccess code but im just getting a 404 Not Found. Any help would be appreciated.
Options +FollowSymLinks
RewriteEngine on
#don't use .php file extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
#test get peram to directory
RewriteRule ^([0-9]+)/$ /index.php?pix=$1
Your code is almost ok. Try this:
RewriteRule ^([0-9]+)$ index.php?pix=$1
Related
I want to make my URL from this:
https://www.website.com/index.php?title=A1-13-05-2021
to this:
https://www.website.com/A1-13-05-2021
And want to access above query string param in index.php as $_GET['title'].
For this, I have written the below .htaccess code. But that's not working
RewriteEngine On
RewriteRule ^index?$ index.php
RewriteRule ^index/([a-zA-Z0-9\-]+) index.php?title=$1
Can anyone please help me to know where I am doing wrong?
Thanks.
With your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for handling non-existing pages here to index.php file.
RewriteRule ^(A1-13-05-2021)/?$ index.php?title=$1 [QSA,NC,L]
Generic Rules: In case you want to make it Generic rules then try following rules only.
RewriteEngine ON
##Rule for handling non-existing pages here to index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(A1-\d{2}-\d{2}-\d{4})/?$ index.php?title=$1 [QSA,NC,L]
I'm a beginner using htaccess and I don't know how to do what I want. I'd like to understand what I'm doing so I'd really appreciate if you can help me give me some advices for ver (very!) beginners... :)
I'd like to:
Redirect xxx.php, xxx.html or any extension to xxx (without extension)
Now, my htaccess is
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
and it works but just if I write xxx. But if I write xxx.php (I see the page :(, I'd like to redirect to xxx) and if I write xxx.html it doesn't show nothing.
Finally. I've like to rewrite variables to friendly links
i.e. If I have xxx.php?id=1 > I would like to redirect to xxx/username
Thank you in advance
Best wishes and merry christmas! :)
Try this:
I use this code already.
Rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
Put this in your htaccess file && then check for files without extension.
Thanks
Try adding these rules to your htaccess file:
RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
RewriteRule ^ /%1 [L,R=301]
If you need to do the same with with .html extensions, then change the php part of that condition to (php|html?).
On the start i want you to take notice, i did try finding solution in google, or in stackoverflow. I found some tips, but they didn't work for me, or i simply failed following instructions.
So, here is my site directories:
www.domain.pl/index.php <--index file
www.domain.pl/images/ <--images folder
www.domain.pl/styles/ <--styles folder, for now just 1 css file
www.domain.pl/script/ <--scripts folder, js files, and 1 php file called with include
www.domain.pl/font/ <--font files
Now, when i open my website with www.domain.pl or www.domain.pl/index.php it works like a charm. But i want to be able to add some parameter for example www.domain.pl/index.php?action=dosmth, but it doesn't look good for a users, so thats the place where I wanted to use mod rewrite.
Now comes tricky part, i want it to look like www.domain.pl/index/actionparam/ but when i do that, I get error in console, saying my images, scripts, and css cant be loaded/found. (i tried rewriting it like that: RewriteRule ^index/([^-]+)/script/jquery-1.7.1.min.js$ script/jquery-1.7.1.min.js [L] but I cant use it for every single image, script, css, or font file. There need to be better way.
So, my mod rewrite so far:
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.pl/$1/ [L,R=301]
RewriteRule ^index.html$ index.php [L]
RewriteRule ^index/$ index.php [L]
RewriteRule ^index/([^-]+)/$ index.php?action=$1 [L]
First part, i am trying to add "slash" at the end of url, if user didnt put it there.
http://domain.pl/index->http://domain.pl/index/ or
http://domain.pl/index/myaction->http://domain.pl/index/myaction/
Question
Is it possible to somehow skip folders with images, scripts etc when rewriting it? Or how could i rewrite all images at once?
Additional question
http://domain.pl/myaction/ redirect straight to http://domain.pl/index.php?action=myaction right away, without need of putting /index/ in there? Yes, i am learning mod rewrite.
You don't have to include index in the request, only the parameter. Example:
Request: http://domain.pl/myaction
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Exclude existing files and directories.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
# Get the parameter and pass it to index.php
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/? /index.php?action=$1 [L,NC]
I am looking for a way to get rid off the .php extension from my file i have just got a static website with index.php and map.php
I have tried lots of different tutorials but none work i just want the following.
http://example.co.uk/map.php becomes http://example.co.uk/map/
and
http://example.co.uk/index.php becomes http://example.co.uk/
Can you do this with a static file i have tried so many different options and none have worked for me.
i have tried this.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^map/(.*)/$ map.php
Any help please.
Try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^map/?$ map.php [NC,QSA,L]
RewriteCond %{SCRIPT_FILENAME} \/index\.php [NC]
RewriteRule (.*) http://www.domain.com/ [R=301,L]
# if you have more than one file like map, you can use this
# this will redirect everything to .php like: test/ => test.php
# RewriteRule ^([a-z0-9_\-]+)/?$ $1.php [NC,QSA,L]
I am trying to write RewriteRule to redirect www.myweb.com/download/blabla.zip to > www.myweb.com/download/download.php?filedownload=blabla.zip
this is my .htaccess
Options +FollowSymlinks
RewriteBase /download/
RewriteEngine on
RewriteRule ^(.*)$ download.php?filedownload=$1 [L]
the .htaccess located in the folder /download
and the download.php file located also in the folder /download
but it doesnt work, no idea why...
Can you help me?
BTW: the mod_rewrite is enabled.
Thanks.
Your RewriteRule is recursing on itself, and passing download.php as the parameter to itself.
You can try either of the following.
To match only zip/exe:
RewriteRule ^(.*\.(zip|exe))$ download.php?filedownload=$1 [L]
To exclude download.php from matches, place this before your RewriteRule:
RewriteCond %{REQUEST_FILENAME} !download.php