last day (14 days later) » 

11:28 AM
0
A: .htaccess: Some Rewrites working while others not

anubhavaIt is because you're not using anchors in your regex and 3rd rule with svb is overriding books/svb. Try these rules: Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^spanish-vocabulary-bible/?$ books/?bb=spanish-vocabulary-bible [NC,L,QSA] RewriteRule (?:^|/)svb/?$ books/?b...

 
Why do I need an anchor if there's no regex involved? I am just trying to redirect books/svb to books?bb=spanish-vocabulary-bible. There's no variable in the first argument. Am not sure I understand the answer.
Besides, it's only the second rule that's not working. All others are redirecting fine, but you have suggested adding /?$ to every single one of them.
Also, how can a rule on svb override one on books/svb? Note that I haven't used the caret sign.
 
1. Where is this .htaccess located? 2. Are there more rules or any other .htaccess in your system? 3. What is the full URL you're using to test it?
 
The file is in my root directory as usual and is the only htaccess I have. And yes there are a bunch of other rules but none that could interfere with this one.
 
I had 3rd question as well. Anyway you need to update the question with full .htaccess
 
Sorry, didn't notice the 3rd question. The URL I am trying is: peppyburro.com/books/svb
 
11:28 AM
Is books/ a real directory?
 
No it isn't. But neither are emails, svb, or tome all of which are redirecting successfully.
Hi, first off, thanks for taking the time
 
welcome
When you write in your rule books? what handler should it be running? Is books a PHP file?
 
I have a books.php file in my root
 
oh ok got it
 
so when you visit peppyburro.com/books, it loads books.php
will it help if i showed you my directory structure?
 
11:31 AM
yes pls show it
 
1 sec
inside this php file, i'm calling another file called assets/books_body.php to load the body content
what i needed was for one to visit peppyburro.com/books/<something> and get redirected to peppyburro.com/books?bb=<something> without changing the url in the address bar.
 
ok try my updated code starting with 1st line as Options +FollowSymlinks -MultiViews
 
gimme a moment...
 
ok
 
other than -MultiViews, is this what I should do?
RewriteRule books/svb http://peppyburro.com/books?bb=spanish-vocabulary-bible [NC,L]
oops, dunno how to paste it without it getting truncated here
 
11:38 AM
you need to take everything from my answer and completely clear browser cache
 
is there any reason I should alter the lines for email and others that are already working?
just wondering if it'll break anything else on the file
 
ok leave email rule
 
lemme try
 
ok
completely clear browser cache first
 
yeah am trying it in incognito mode so cache shouldnt be a problem :)
okay here's the results:
 
11:45 AM
even in incognito regular caching is used so better to clear it completely or use some command line tool like curl to test
 
now peppyburro.com/books/svb is showing me the results of books?bb=spanish-vocabulary-bible. But, when I directly try to access the actual link, it breaks down
oh yes i did clear the cache anyway. forgot to tell ya. sorry. but you can try visiting the link...it's still breaking down parts
for example, it's not loading the stylesheet files for the header...i guess that path needs to be changed but i don't know what reference to use for that path
also, like i said, now directly visiting the ugly url (one with ?=) is not showing the right page anymore
 
so I am on peppyburro.com/books/svb now, what is not working?
 
you can compare it with the navbar on the homepage
see the header? it's not recognizing the stylesheet
also, try visiting peppyburro.com/books?bb=spanish-vocabulary-bible directly...it throws a 404
 
yes that is on purpose, try: http://www.peppyburro.com/books.php?bb=spanish-vocabulary-bible
Now add this just below <head> section of your page's HTML: <base href="/" /> to fix your css/js paths
 
this worked...lemme see if this affects any other page or download links.
yes as i suspected...all links now need a .php. can this not be avoided by any chance?
for example, /about isn't working anymore, /about.php is
all links on my site point to php files and you obviously don't want to be having to add .php to them, right?
 
11:57 AM
see updated rule now to add .php automatically
 
will this not add .php to every file on the server? That wouldn't be good either because I have some downloadables with zip and other extensions as well. :(
ohh, ok, now peppyburro.com/books/svb is throwing an error 500
do you think all of this can be avoided if i just create a books folder and move the books.php file to this folder as index.php?
 
can you show paste relevant part of your .htaccess here?
 
i have completely replaced the contents with what you have updated in the answer for now.
this is all i have in my htaccess right now:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z.]+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^spanish-vocabulary-bible/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]

RewriteRule (?:^|/)svb/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]

RewriteRule ^emails/?$ http://peppyburro.com:2082/cpsess5562708231/frontend/paper_lantern/mail/pops.html [N
 
ok try first lines as:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^([a-z.]+)$ [NC]
    RewriteRule ^ %{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

    RewriteRule ^spanish-vocabulary-bible/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]

    RewriteRule (?:^|/)svb/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]
I removed -MultiViews and .php rule
btw peppyburro.com/books/svb looks fine with css
 
yes it works...now all i need to do is figure out a way for it to honor the associated stylesheet
i am assuming this will not affect any other extensions on my server such as zip or pdf
 
12:11 PM
no it won't
 
by the way, could you please explain what the first rewriterule does here?
RewriteRule ^spanish-vocabulary-bible/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]
never mind...got it
 
it means if URL is http://www.peppyburro.com/spanish-vocabulary-bible then internally load http://www.peppyburro.com/books.php?bb=spanish-vocabulary-bible WITHOUT changing URL
 
so looks like when i run /spanish-vocabulary-bible, it recognizes the stylesheets but when i run /books/svb, it doesn't
 
I think you missed my instructions on that
 
the base=/ one, right?
 
12:14 PM
You can add this just below <head> section of your page's HTML: <base href="/" />
 
worked like a charm...thank you! I hope the same tricks work on all other query-type pages as well. :)
Just gimme a day or two and I will place a bounty on the question for your efforts. SO wouldn't allow me to do it before that.
 
sure take your time for that and I'm really glad it worked for you
that is always the biggest satisfaction
 
once agan, thank you tons. i was going crazy with this stupid problem.
 
you're most welcome
 
my knowledge of htaccess has taken a big leap today. :)
have a good day ahead. bye
 
12:17 PM
:) take care & bye
 
could you please lend me a helping hand with making the argument variable instead of the hardcoded spanish-vocabulary-bible?
sorry to be back on your neck
for example, right now, it's peppyburro.com/books/spanish-vocabulary-bible redirecting to peppyburro.com/books?bb=spanish-vocabulary-bible
 
yo mean this wat: RewriteRule ^(spanish-vocabulary-bible)/?$ books.php?bb=$1 [NC,L,QSA]
 
what if i want spanish-vocabulary-bible to be variable...like $1
i have this right now: RewriteRule ^svb/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]
so should i just replace the final spanish-vocabulary-bible to $1?
that won't work i guess because that still leaves the svb bit hardcoded
 
you can keep 2 rules as:

RewriteRule ^(spanish-vocabulary-bible)/?$ books.php?bb=$1 [NC,L,QSA]

RewriteRule (?:^|/)svb/?$ books.php?bb=spanish-vocabulary-bible [NC,L,QSA]
 
didn't work :(
 
12:29 PM
fow whichh url?
 
now peppyburro.com/books/spanish-vocabulary-bible is not working
i need the spanish-vocabulary-bible but in this particular url to be variable
so one could try peppyburro.com/books/<something> and go to peppyburro.com/books?bb=<something>
 
so you want anything after books/ to be a variable?
 
yeah
and i also want peppyburro.com/svb to be hardcoded for this particular book, i.e. peppyburro.com/books?bb=spanbish-vocabulary-bible
 
ok got it
ok try: RewriteRule ^books/([\w-]+)/?$ books.php?bb=$1 [NC,L,QSA]
 
nope...it's leaving me back at peppyburro.com/books without changing the url
now if you try visiting peppyburro.com/books/spanish-vocabulary-bible, it doesn't redirect.
 
12:34 PM
URL won't change at all
 
i mean the url remains correct (peppyburro.com/books/spanish-vocabulary-bible) but the page displayed is of peppyburro.com/books
it's not going to the spanish-vocabulary-bible page
 
yes that is the problem with MultiViews. Can you keep URL as http://www.peppyburro.com/book/spanish-vocabulary-bible i.e. book instead of books?
then rule will be: RewriteRule ^book/([\w-]+)/?$ books.php?bb=$1 [NC,L,QSA]
and it will surely work
 
is that because there's a file called books.php?
 
yes
that makes MultiViews takes over our rule
if you keep book/ then it will work
 
i see. well that will be a tad inconsistent with the rest of the site. for example in another case i have dictionary. this trick wont work there because i cant change dictionary to dictionaries. instead, can i try creating a folder named books and move books.php there as index.php?
 
12:39 PM
yes sure you can but then rule will be: RewriteRule ^books/([\w-]+)/?$ books/index.php?bb=$1 [NC,L,QSA]
 
that will be in the same htaccess or should i have another htaccess inside the books folder?
 
better have another inside books/ folder with slightly different rules
i.e. RewriteRule ^([\w-]+)/?$ index.php?bb=$1 [L,QSA]
 
thought as much. thanks for confirming. well, let me fix it all up and then if i need anything (hopefully not), i will touch base with you by tomorrow. thanks again!
 
sure let's talk tomorrow :)
best of luck
 
thanks. take care.
 
12:42 PM
thanks and you too
 

last day (14 days later) »