The previous less described question has removed.
Specified question:
• The question have described in the statement. Please read at-least once..
• My goal is to have friendly url. So I do some actions..
it simply works with: ^thread/[(0-9)+]/(*?) $thread.php?id=$1
but not working with this: ^thread/[(0-9)+]/page/[(0-9)+]/(*?) $thread.php?id=$1&page=$2
i discovered changing 'thread' (for 2) into another word like..
^anotherWord/[(0-9)+]/page/[(0-9)+]/(*?)
$thread.php?id=$1&page=2
(above) is working fine..
but many of you are doing such..
I mean, you have
blog/id/1/blog-title.html
blog/id/1/page/2/blog-title.html
blog/edit/id/1
all for your blog.php
blog.php?id=1
blog.php?id=1&page=2
blog.php?id=1&edit
Here, id, page and blog-title can have any value. Actually id and page is a $_GET var. with this id i can pull out the blog title from db.
So what to do to get working friendly url? Please reply me..
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteRule ^forum/(\d+)/response/[^/]*$ post.php?id=$1 [NC,QSA,L]
RewriteRule ^(thread|forum)/(\d+)(?:/page/(\d+))?/[^/]*$ $1.php?id=$2&page=$3 [NC,QSA,L]
Related
I have this link that works and leads to the correct article:
Article
however I do not want the link to display the id number I want the link to look like this:
Article
This is what I have in my .htaccess file, any help would be appreciated, thanks:
Options -MultiViews
ReWriteEngine On
RewriteBase /
RewriteRule ^news/(\d+)/([\w-]+)/?$ news.php?id=$1&linkAddress=$2 [NC,L,NE]
Is it poosible to remove the 21 id from the link but still use the id to get the variables from database. thanks.
Could you please try following, written based on samples. Please make sure you clear your browser cache after placing these urls in your .htaccess file. Also make sure this new rule is above your already existing news.php rule(shown in your samples).
RewriteEngine ON
RewriteRule ^(news)/(Hello-World)/?$ $1/21/$2 [NC,L]
##Placing OP's rule to serve urls starting with news with news.php in backend.
RewriteRule ^news/(\d+)/([\w-]+)/?$ news.php?id=$1&linkAddress=$2 [NC,L,NE]
I've tried for ages to fix this problem that I have.
On my website I have rewriten some links with the htaccess file. The htaccess file currently looks like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sideID=$1
RewriteRule ^([a-zA-Z0-9_!-]+)/([a-zA-Z0-9_!-]+)/([a-zA-Z0-9_!-]+)$ index.php?sideID=$1&id=$2&title=$3
RewriteCond %{HTTP_HOST} ^www\.mypage\.no$
RewriteRule ^/?$ "http\:\/\/mypage\.no\/" [R=301,L]
The first rule rewrites from:
http://mypage.com/index.php?sideID=home
To this:
http://mypage.com/home
The first rule rewrites from:
http://mypage.com/index.php?sideID=b&id=12&title=a-great-blog-post
To this:
http://mypage.com/b/12/a-great-blog-post
Soo they do what I want too when it comes to rewriting I guess. BUT, the problem is that if im now navigated to any blog post on the site and then tryies to navigate back to whatever other link lets say http://mypage.com/home it will add http://mypage.com/b/12/home instead. That can of course be fixed easily by just using absolute URL's in the navigation. But when I try to make a XML Sitemap, the bot will index every page for each blog ID like so: http://mypage.com/b/12/home, http://mypage.com/b/13/home, http://mypage.com/b/14/home and so on for each blog ID and pagename.
Is there a way to make sure the RewriteRule's apply seperatly or set a condition for them or something like that?? I am a bit noob in this area.
I beg you, please help me! :)
I apologize if the title isn't quite clear as I am new to mod_rewrite and I am not sure how to phrase the question correctly.
I want to rewrite a fancy url such as http://www.url.com/module/subdirectory/another_subdirectory/page to http://www.url.com/d_1=module&d_2=subdirectory&d_3=another_subdirectory&page=page. The number of subdirectories varies so the parameter d_* can be dynamic (trying to keep it between d_1 and d_9 though). The fancy url can also have its own query string and it needs to be rewritten to occur after the page parameter.
I did a read through of Apache's mod_rewrite and regex documentation and spent some time searching on Google and Stackoverflow for an answer to this but could not find anything for this specific problem. Any help on this problem from someone much more knowledgable would be greatly appreciated.
You can try something like below in the .htacess in the root directory, though you need to finish the cases up to 9.
I am also assuming that your CMS application is index.php. If not replace with correct .php file
RewriteEngine on
RewriteBase /
#one subdir
RewriteRule ^module/([^/]+)/([^/]+)$ index.php?d_1=module&d_2=$1&page=$2 [QSA,L,NC]
#two subdir
RewriteRule ^module/([^/]+)/([^/]+)/([^/]+)$ index.php?d_1=module&d_2=$1&d_3=$2&page=$3 [QSA,L,NC]
#three subdir
RewriteRule ^module/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?d_1=module&d_2=$1&d_3=$2&d_4=$3&page=$4 [QSA,L,NC]
Alteration of Ulrich's code that doesn't need as much repeating, by making the subdir-parts optional. The last part always maps to page:
RewriteRule ^(module)/(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?([^/]+)$ index.php?d_1=$1&d_2=$2&d_3=$3&d_4=$4&d_5=$5&d_6=$6&d_7=$7&d_8=$8&page=$9 [QSA,L,NC]
Though I would prefer to use some php code for this.
$dirs = expode('/', $_SERVER['REQUEST_URI']);
array_shift($dirs);//remove first empty string.
$page = array_pop($dirs);//get last part of the url.
I am currently trying to put a RewriteRule into my .htaccess file for my Magento website that will allow me to write a category URL in the following way:
http://mydomain.com/dir/<direction>/order/<order>/<Magento category URL path>.html
What I am basically looking to do is use my robots.txt file to make some of the category URLs not appear (specifically when you apply a different sort order to the category).
So let's assume I have the following URL:
http://mydomain.com/dir/asc/order/sales_index/footwear/mens-work-boots/motorcycle-boots.html
I would like that to be rendered just as if it the URL was:
http://mydomain.com/footwear/mens-work-boots/motorcycle-boots.html?dir=asc&order=sales_index
The code I have put in my .htaccess file is as follows:
RewriteRule ^dir/(.*?)/order/(.*?)/(.*?)$ $3.html?dir=$1&order=$2
For some reason, when I have this in there, I get a 404 error. Can someone point me in the right direction to make this work for me?
I tried with this on my server
RewriteRule ^(.*)/dir/(.*?)/order/(.*?)/(.*?)$ $4.html?dir=$2&order=$3 [R,L]
and when i issue request
http://myserver/dir/asc/order/sales_index/footwear/mens-work-boots/motorcycle-boots.html
i get proper redirection to
http://yuave.dev:81/footwear/mens-work-boots/motorcycle-boots.html.html?dir=asc&order=sales_index
May be you are missing [L] flag on your request.
The web server is Apache. I want to rewrite URL so a user won't know the actual directory. For example:
The original URL:
www.mydomainname.com/en/piecework/piecework.php?piecework_id=11
Expected URL:
piecework.mydomainname.com/en/11
I added the following statements in .htaccess:
RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]
RewriteRule ^(w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]
Of course I replaced mydomainname with my domain name.
.htaccess is placed in the site root, but when I access piecework.mydomainname.com/en/11, I got "Object not found".(Of course I replaced mydomainname with my domain name.)
I added the following statements in .htaccess:
RewriteRule ^/(.*)/en/piecework/(.*)piecework_id=([0-9]+)(.*) piecework.mydomainname.com/en/$3
Of course I replaced mydomainname with my domain name.
.htaccess is placed in the site root, but when I access piecework.mydomainname.com/en/11, I got "Object not found".(Of course I replaced mydomainname with my domain name.)
What's wrong?
Try using RewriteLog in your vhost or server-conf in order to check the rewriting process. Right now you just seem to guess what mod_rewrite does.
By using RewriteLogLevel you can modify the extend of the logging. For starters I'd recommend level 5.
PS: Don't forget to reload/restart the server after modifying the config.
Here's a quick overview of what's happening:
RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]
First, the question mark is supposed to be at the end.
$1 would (should) match anything that is not 'www' 0 or 1 times.
$2 matches anything that is not a character 1 or more times, which theoretically would match a blank space there but likely would never match anything.
Then it requires '.mydomainname.com' after those two groupings.
Your first two conditions are looking for two separate groupings.
I'm not sure exactly how you're trying to set up your structure, but here is how I would write it based on your original and expected URL's:
RewriteCond %{HTTP_HOST} !^www\.mydomainname\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomainname\.com$ [NC]
RewriteRule ^(\w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]
Basically, your first condition is to make sure it's not the URL beginning with 'www' (it's easier to just make it a separate rule). The second condition makes it check any word that could possibly be in front of your domain name. Then your rewrite rule will redirect it appropriately.
Get rid of the last .htaccess line there in your question...
Someone please correct me if I typed something wrong. I don't remember if you have to have the '\' in front of '\w' and '\d' but I included them anyways.
You are doing it backwards. The idea is that you will give people the friendly address, and the re-write rule will point requests to this friendly, non-existent page to the real page without them seeing it. So right now you have it only handling what to do when they go to the ugly URL, but you are putting in the friendly URL. since no rule exists for when people put the friendly URL directly, apache looks for it and says "Object not Found"
So add a line:
RewriteRule piecework.mydomainname.com/en/(*.) ^/$3/en/piecework/$3?piecework_id=([0-9]+)(.*)
Sorry, that's quite right, but the basic idea is, if they put in the URL you like, Apache is ready to redirect to the real page without the browser seeing it.
Update
I'm way to sleepy to do regex correctly, so I had just tried my best to move your example around, sorry. I would try something more simple first just to get the basic concept down first. Try this:
RewriteRule www.mydomainname.com/en/piecework/piecework\.php\?piecework_id\=11 piecework.mydomainname.com/en/11
At the very least, it will be easier to see what isn't working if you get errors.