I'd like to ask if it's possible to use a dynamic url and GET at the same time.
Let's say my current dynamic url is: https://yourdomain.com/blog/this-is-a-title
Would it be possible to make this work too: https://yourdomain.com/blog/this-is-a-title?action=delete
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?id=$1
The dynamic url mentioned first works fine, but I want to make the second work as well.
This is my .htaccess - hope it helps.
PS: I know that the regex in my htaccess isn't correct, it's just an example.
Have your .htaccess Rules file in following manner. Please make sure that your htaccess Rules file is present in root folder(where blog and htaccess both are residing in it; htaccess shiouldn't be inside blog folder; should be place same folder with it). Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Newly added rules here...
RewriteBase /blog/
RewriteCond %{THE_REQUEST} \s/blog/(?:[^?]*)?action=(\S+)\s [NC]
RewriteRule ^ index.php?action=%1 [L]
##Old Rules OP's htaccess ones.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?id=$1
Related
The website I'm working on is using some cms. I need to add a static website to this. When I put mypage.html in the main directory and go to www.website.com/mypage.html it works. I would like the page to be accessible without '.html' ending. I experimented with editing htaccess files but always end up with error of too many redirections.
What I entered were various combinations, for example
Redirect 301 http://website.com/mypage http://website.com/mypage.html
The htaccess file I'm using looks like this:
:Location /*.php
Use php54
:Location
RewriteEngine On
DirectoryIndex index_prod.php
Options -Indexes
RewriteRule ^.*\.(css|png|swf|js|gif|jpeg|jpg|flv|pdf|doc)$ - [L]
RewriteRule ^net2ftp - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^/?$ plug.html [L]
#RewriteCond %{REQUEST_URI} !=/
RewriteRule ^/?.* index_prod.php
I'm looking for tips or to be explicitly told what and where to put in htaccess file to make it work (if it's possible)
Could you please try following, considering that you want without extension file URLs to be served by html extension files. Also since you didn't mention any specific condition before RewriteRule hence that redirection errors are coming to it, because its keep on redirecting in lack of any condition/check's presence(till its maximum redirection limit is crossed).
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [NC,L]
I made a dynamic website but to be indexed on Google, I understand that I have to rewrite all URLs.
Every URL is in this form:
www.mysite.com/folder/?page=name
Where name is the name (with a lot of imagination) of pages.
I want that URLs in this form:
www.mysite.com/folder/name.php
To do so I need to use the .htaccess file but I can't understand what I should write in it. I read a lot of pages on internet but still I can't understand what should I do or what code I have to use.
Try adding this rule to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+folder/(?:index.php|)\?page=([^&\ ]+)
RewriteRule ^ /folder/%1.php? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder/([^/.]+)\.php$ /folder/?page=$1 [L]
I was looking for a simple .htaccess configuration that just convert /some_uri to /some_uri.php. Most examples in community are more complicated than I require. I was trying the following, but it didn't work:
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^(.*)$ ./$1.php
Please help. Thank you.
You need to make sure that the rule does not match itself. In other words, you need to make sure the rule does not match if the url already ends on php. Besides that you probably want to prevent that the rule matches if it already points to a file that exists, so that you can normally serve css/js/images without it trying to append php to it.
RewriteCond %{REQUEST_URI} !\.php$ #Does not end with .php
RewriteCond %{REQUEST_FILENAME} !-f #Requested url is not an existing file
RewriteRule ^ %{REQUEST_URI}.php [L]
http://localhost/clean_urls/user/whtffgh redirect fine to this http://localhost/clean_urls/user/whtffgh/ (pretty much anything I put there works).
http://localhost/clean_urls/user/cohen however, redirects to this
http://localhost/clean/ and I have no idea why. It should just add a /
Heres my .htaccess code
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /clean_urls/user/$1/ [L,R=301]
RewriteBase /clean_urls/user/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?user=$1
</ifModule>
UPDATE:
The code works besides when I put cohen as the username. The second part of the .htaccess file is making user/index.php?user=username look like user/username so its just a $_GET variable that looks nice in the url and is SEO friendly (apparently).
I am just learning this stuff and making a webapp to try it out so not really sure where its going but I do think I will need another variable on the end. http:://localhost/clean_urls/user/fred/someverb
You misunderstand what the RewriteBase directive is used for. It helps the rewrite engine in a "per directory" context to convert the relative URIs to the correct filename equivalent.
You should only have one RewriteBase directive per .htaccess file. The rewrite engine by default will use the lowest .htaccess file on the path with the RewriteEngine On directive set.
So in DOCroot (that is the directory where a "GET /xxx" is mapped to, this should be
RewriteBase /
If your .htaccess file is in DOCroot/clean_urls/user then it should have
RewriteBase /clean_urls/user/
How do you want to decode URIs of the form http:://localhost/fred or are you only wanting do process URIs of the form http:://localhost/clean_urls/user/fred/. What about http:://localhost/clean_urls/user/fred/someverb?
Let me know and where you are putting you .htaccess then I can give you the right content.
I have created a simple mod rewrite for my site:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(cgi-bin|css|images|js|gfx)/?.*$ [NC]
RewriteRule ^filter/model/([^/]*)/mins/([^/]*)/texts/([^/]*)/freegifts/([^/]*)/network/([^/]*)/merchant/([^/]*)$ /fiverrr.php?model=$1&mins=$2&texts=$3&freegifts=$4&network=$5&merchant=$6 [L]
but it doesn't seem to be working (as in all the images/js etc don't show up)
e.g. http://mydomain.com/filter/model/Sony+Ericsson+Xperia+Arc+S+White/mins/+3000/texts/+-1/freegifts/FREE+Nintendo+3DS+Black/network/Orange/merchant/
original url: http://mydomain.com/fiverrr.php?model=Sony+Ericsson+Xperia+Arc+S+White&mins=+3000&texts=+-1&freegifts=FREE+Nintendo+3DS+Black&network=Orange&merchant=Contract
Where am I going wrong, and is this the best method?
Thanks so much
Try to put there another condition - htaccess will rewrite it only if requested file does not exist:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^filter/model/([^/]*)/mins/([^/]*)/texts/([^/]*)/freegifts/([^/]*)/network/([^/]*)/merchant/([^/]*)$ /fiverrr.php?model=$1&mins=$2&texts=$3&freegifts=$4&network=$5&merchant=$6 [L]
Also I recomend you to check full paths. Check if you have images in HTML code like: http://mydomain.com/images/img.jpg - relative paths like ./../images/img.jpg will not work!