Alright, so here is what I'm hoping for...
Any request to this
http://www.fileorchard.com/3451928347592
will rewrite to http://www.website.com/joke.php?j=3451928347592
but also, I would like this to be possible as well
http://www.website.com/3451928347592-dswkfjawe/asdoiw-aweofiwe
Essentially, I would like to grab the numbers, and ignore anything after them.
This is what I have so far
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)/?$ joke.php?j=$1 [NC]
This works for just the simple http://www.website.com/3451928347592
but the rest don't work.
Thanks.
Maybe RewriteRule ^([0-9]+)(.*)/?$ joke.php?j=$1 [NC] ?
Related
I need to do some redirecting to get some internal links to work but I'm having a complete block.
The url would be http://www.something.com/faqs/What_happens_if_I_move_home?
redirected to http://www.something.com/faqs/index/What_happens_if_I_move_home?
but it must look like the original url. I'm sure there is a simple answer but rewrite rules and regex are a mystery to me at times.
I did try RewriteRule ^faqs(/.*)?$ /faqs/index$1 [R,L,NC]
amongst many others!
try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/faqs/index
RewriteRule ^faqs/(.*) /faqs/index/$1 [L,NC]
I have this address
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
that I would like to make it a lot shorter and more SEO friendly to something like (I don't know ... open to suggestions) http://www.nfrases.com/tag/10/508 or http://www.tag10name.nfrases.com/508
I need help with how to code this, because a simple thing as trying to make the address always http://www.nfrases.com case the user goes to http://nfrases.com or www.nfrases.com I tried and failed :(
Used this code by the way:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
becomes
http://www.nfrases.com/10/508
with this in your .htaccess
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /tag.php?id_tag=$1&id_frase=$2 [L,QSA]
Untested. Let me know if it works for you.
I am fiddling around with .htaccess and mod_rewrite. I have a site that has two types of URLs which I want to rewrite:
/index.php?nav=$2
/index.php?nav=41&intNewsId=$3 -- 41 is static, the news nav is always 41
I want to rewrite them to:
/pagename/id
/news/pagename/id
I already made a piece of code that works, BUT if I add the last line the second line stops working, and I can imagine thats because the conditions in the third block are also true for the second block. But I cant figure out how to use conditions right. (Both blocks work individual)
Options +FollowSymlinks
RewriteEngine on
# Reroute rules that end on /
RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$ /$1/$2/ [R]
# Make the system understand pagename/96
RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=$2
# Make the system understand news/pagename/99
RewriteRule ^(.*)\/(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=41&intNewsId=$3
I tried everything I could think of, but I'm not too familiar with this regex style of typing or conditional blocks in htaccess.
Solution:
I fixed my own code, I just stripped the second $ so the condition didnt interfere with the last one
Options +FollowSymlinks
RewriteEngine on
# Reroute rules that end on /
RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$ /$1/$2/ [R]
# Make the system understand pagename/96
RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/ /index.php?nav=$2
# Make the system understand news/pagename/99
RewriteRule ^(.*)\/(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=41&intNewsId=$3
Thanks for the answers all!
Try this:
RewriteRule ^news/.+/([^/]*)$ /index.php?nav=41&intNewsId=$1 [L]
RewriteRule ^.+/([^/]*)$ /index.php?nav=$1 [L]
Another approach, perhaps slightly more concise:
RewriteRule ^pagename/(\d+)$ index.php?nav=$1
RewriteRule ^news/pagename/(\d+)$ index.php?nav=41&intNewsId=$1
Try this:
# Make the system understand pagename/96
RewriteCond %{REQUEST_URI} ^/pagename/([0-9]*)
RewriteRule .* /index.php?nav=%1
# Make the system understand news/pagename/99
RewriteCond %{REQUEST_URI} ^/news/pagename/([0-9]*)
RewriteRule .* /index.php?nav=41&intNewsId=%1
I don't know if they really using a RewriteRule (Apache mod_rewrite) for this, but if we append an URL after the URL of bit.ly (ie: http://bit.ly/http://www.somesite.com/), it takes the URL appended as a parameter (http://bit.ly/?u=http%3A%2F%2Fwww.somesite.com%2F).
Someone knows how to do that, maybe with a RewriteRule or something else? If so, what can be the regex to manage this?
Thanks!
I would imagine their rewrite rule looks something like this:
RewriteRule ^(http.*)$ ?u=$1?%{QUERY_STRING} [R]
Couldn't help but fiddle around with this: Accepts multiple protocols and avoids appending the ? if there is no query string:
RewriteCond %{QUERY_STRING} (^$)
RewriteRule ^((http|ftp).*)$ ?u=$1 [B,R,L]
RewriteRule ^((http|ftp).*)$ ?u=$1?%{QUERY_STRING} [B,R,L]
It's probably something in these lines:
<IfModule mod_rewrite.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
And then have index.php do a:
search database to see if link is ok or flagged (badware, spam, etc)
mark visit in stats database
throw http 301 headers on the user for a proper redirect
I'm still pretty lost with mod_rewrite as its incredibly new to me. I'm trying to set up a few rules for better urls. However, after playing around with it for awhile it appears that it only ever uses the first rule listed. For example, if i go to "/frontpage/some-post-slug" it works perfectly but if i go to "/page/some-page-slug" I get a 500 Internal Server Error. Does anyone have any idea what would be causing this?
my .htaccess file is in full below:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^frontpage/([A-Za-z0-9-]+)*$ /frontpage/?slug=$1 [NE,L]
RewriteRule ^page/([A-Za-z0-9-]+)*$ /page/?slug=$1 [NE,L]
</IfModule>
Thanks for any help!
What happens if you remove the * before the $-sign? I never use them and my rules are pretty much the same as yours.