"RewriteBase: argument is not a valid URL" error - php

I'm trying to configure .htaccess of my website.
http://213.175.210.49/~incisozl/ is the temporary url to the root(~/public_html/).
when I try to rewrite the url at .htaccess i get an
/home/incisozl/public_html/.htaccess: RewriteBase: argument is not a valid URL, referer: ht tp://213.175.210.49/~incisozl/inci-sozluk/somestring
error.
my rewrite rule is;
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /index.php [L]
RewriteRule ^inci-sozluk/([^\.\?/]+)/([0-9]+)/?$ /seo.php?process=word&q=$1&sayfa=$2 [L]
RewriteRule ^inci-sozluk/([^\.\?/]+)?$ /seo.php?process=word&q=$1 [L]
RewriteRule ^inci-sozluk/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=word&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluktest/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=wordtest&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluk-bugun/([^\.\?/]+)/([0-9]+)/?$ /seo.php?process=wordbg&q=$1&sayfa=$2 [L]
RewriteRule ^inci-sozluk-bugun/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=wordbg&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluk-dun/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=worddn&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluk-dun/([^\.\?/]+)/([0-9]+)/?$ /seo.php?process=worddn&q=$1&sayfa=$2 [L]
RewriteRule ^inci-sozluk-ters/([^\.\?/]+)/([0-9]+)/?$ /seo.php?process=wordts&q=$1&sayfa=$2 [L]
RewriteRule ^inci-sozluk-ters/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=wordts&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluk-cvpters/([^\.\?/]+)/([0-9]+)/?$ /seo.php?process=cvpwordts&q=$1&sayfa=$2 [L]
RewriteRule ^inci-sozluk-cvpters/([^\.\?/]+)/([0-9]+)/([0-9]+)/?$ /seo.php?process=cvpwordts&q=$1&sayfa=$2&gid=$3 [L]
RewriteRule ^inci-sozluk-ileti/([0-9]+)/?$ /seo.php?process=eid&eid=$1 [L]
RewriteRule ^inci-sozluk-ileticvp/([0-9]+)/?$ /seo.php?process=cvpeid&eid=$1 [L]
</IfModule>
btw. it works fine when i use it with www.incisozluk.org pointed domain

That's strange since the only place where this error message is generated is in
cmd_rewritebase() in modules/mappers/mod_rewrite.c and the code is
if (a1[0] != '/') {
return "RewriteBase: argument is not a valid URL";
}
It tests whether the first character of the new value for RewriteBase is a /.
According to the code you've posted that is the case. Could there be another .htaccess file that has an invalid value?

This is archaically old, but I just ran into this and for me the issue was having a slash on both the RewriteBase line and the RewriteRule line's destination. I took the slash off the destination and the error went away!

Related

htaccess url-rewriter page not found

i work in localhost and i need to rewrite url, when i write the url rewrited, a page like : 404 Not found This page not found on this server ...
But the directory is good
I already try to uncomment the line for mod_rewrite in httpdconf.conf
but not work
# URL REWRITING
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^esthetique$ /view/frontend/aestheticView.php [L]
RewriteRule ^forfait-fiancee-normal$ /view/frontend/forfaitFianceeBasicView.php [L]
RewriteRule ^forfait-mariee-normal$ /view/frontend/forfaitMarieeBasicView.php [L]
RewriteRule ^forfait-mariee-belle-dun-soir$ /view/frontend/forfaitMarieePremiumView.php [L]
RewriteRule ^forfaits$ /view/frontend/forfaitsView.php [L]
RewriteRule ^coiffure$ /view/frontend/hairView.php [L]
RewriteRule ^accueil$ /view/frontend/homeView.php [L]
RewriteRule ^mentions-legales$ /view/frontend/legalsView.php [L]
RewriteRule ^maquillage$ /view/frontend/makeupView.php [L]
RewriteRule ^packs-reductions$ /view/frontend/packsView.php [L]
RewriteRule ^politique$ /view/frontend/politiqueView.php [L]
When i go to the url mywebsite.ex/esthetique
He tell me :The requested URL /view/frontend/aestheticView.php was not found on this server.
And he work's when is online

Adding mod_rewrite rule causes server error for whole directory

I have a test folder (example.com/test) with it's own htaccess file. It looks like this:
RewriteEngine On
RewriteRule ^(projects|about)/?$ /test/$1.php [L]
RewriteRule ^sitemap\.xml$ /test/xmlsitemap.php [L]
RewriteRule ^([^/]+)/?$ /test/projects.php?project=$1 [L] #this line causes trouble
RewriteRule ^([^/]+)/([0-9]+)/?$ /test/posts.php?&project=$1&post=$2 [L]
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ /test/posts.php?project=$1&post=$2&title=$3 [L]
When I add this line:
RewriteRule ^([^/]+)/?$ /test/projects.php?project=$1 [L]
to my .htaccess file, everything in the test directory give a 500 Internal Server Error. All the other rules work like they should.
What I'm trying to do is make example.com/test/$1 go to the example.com/test/projects.php?project=$1, with the exceptions of "projects," "about," and "sitemap.xml." There are also numbered posts in each project that have an optional title portion of the url.
The server is running apache 2.2.15.
Please let me know if you need more info or want me to test something.
Try this .htaccess in /test/ folder:
RewriteEngine On
RewriteBase /test/
RewriteRule ^(projects|about)/?$ $1.php [L]
RewriteRule ^sitemap\.xml$ xmlsitemap.php [L]
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ projects.php?project=$1 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ posts.php?&project=$1&post=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ posts.php?project=$1&post=$2&title=$3 [L,QSA]
The rule you have in place now should result in the following:
http://example.com/test/1 -> http://example.com/test/posts.php?&project=test&post=1
Assuming you are not seeing anything useful in access or error logs, then consider adding a rewrite log entry to the host.
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9
This could help to detect something like a redirect loop which could be the cause of the internal server error.

Rewriterule - urls dont change in the browser bar

It's very strange to me, but:
I have a website with guestbook-add.php. I want to show it to the visitors as gasterbuch.html.
So I have written in .htaccess (my real domain has been changed in that listing to http://mywebsite.com/ of course):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ http://mywebsite.com/index.php [L]
RewriteRule ^gasterbuch.html$ http://mywebsite.com/guestbook-list.php
RewriteRule ^eintrag-hinzufugen.html$ http://mywebsite.com/guestbook-add.php
</IfModule>
Now, when I type in the browser http://mywebsite.com/gasterbuch.html, I see the text generated by guestbook-add.php (which is fine).
But in the browser url bar, I see http://mywebsite.com/guestbook-add.php instead of http://mywebsite.com/gasterbuch.html (like it was the 302 redirect).
What am I doing wrong?
Changing
RewriteRule ^index.html$ http://mywebsite.com/index.php [L]
RewriteRule ^gasterbuch.html$ http://mywebsite.com/guestbook-list.php
RewriteRule ^eintrag-hinzufugen.html$ http://mywebsite.com/guestbook-add.php
to
RewriteRule ^index.html$ /index.php [L]
RewriteRule ^gasterbuch.html$ /guestbook-list.php [L]
RewriteRule ^eintrag-hinzufugen.html$ /guestbook-add.php [L]
should work.

Issue with mod_rewrite when accessing directory

My code:
RewriteEngine on
RewriteBase /
RewriteRule ^article/([a-z]+)/?$ index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ index.php?page=$1 [L]
I am using WAMP and had setup a Virtual Host.
In my index.php, there is code to get page passed and checks if it exists(in database). If not, display an error message. It works fine.
Eg: http://mysite/contactus/
But it will not work if I use a a directory name as page_name in the URL. Eg: http://mysite/images/. This will display page not found error (ie. checks database and no page found, so display "not found"). But it will not display images,css(linked file) in the page. Also, it shows http://mysite/images/?page=images in addressbar.
Like that, if I goto js folder which is used to store javascript files, above problem occurs. So, problem is caused if any subdirectory's name is passed as pagename.
How to solve this ?
When http://mysite/images/ is supplied, mod_rewrite is redirecting to http://mysite/images/index.php?page=images instead of http://mysite/index.php?page=images
Edit
Please tell me how to block hotlinking of files and directory, and redirect back to index page or send some browser header error ?
I tried this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*) http://%{HTTP_HOST} [R,L]
RewriteRule ^article/([a-z]+)/?$ /index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ /index.php?page=$1 [L]
Edit
New code(semi-working):
RewriteEngine on
RewriteBase /
# remove trailing slash ONLY if it is not an existing folder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1/ [R,L]
RewriteRule ^article/([a-z]+)/?$ http://%{HTTP_HOST}/index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ http://%{HTTP_HOST}/index.php?page=$1 [L]
This code will clear the problem with not displaying pics and css when a directory name is mentioned. But whatever pagename i specify eg:http://mysite/contactus, it will goto URL: http://mysite/index.php?page=contactus. Even if I use a directory name eg: http://mysite/js, it will goto: http://mysite/index.php?page=js
I am very confused.
RewriteEngine on
RewriteBase /
RewriteRule ^article/([a-z]+)/?$ index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/*$ /index.php?page=$1 [L]
you have to put the slash in front.
Edit: changed the ? to *
My understanding is that your script is for documents only, not images or other resources.
Then you should ignore them right away. Try adding this line right after RewriteBase like this :
RewriteEngine on
RewriteBase /rewrite/
RewriteRule ^/(images|js)/(.*)$ - [L]
RewriteRule ^article/([a-z]+)/?$ index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ index.php?page=$1 [L]
Then these subdirectories would be served right away, thus bypassing the next RewriteRule set.
For the problem with the directories I usually force a slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+[^/])$ $1/ [R]

mod rewrite with get requests

I am having issue passing get variables.
index?p=calendar refers to calendar.php located in pages/calendar.php and index.php is in root.
my URL is localhost/researchportal/calendar/11/2011
Calendar has 2 get variables, month and year. i.e calendar.php?month=11&year=11
here is my rule, but its not working.
RewriteRule ^calendar/([0-9]+)$/([0-9]+)$ index.php?p=calendar&month=$1&year=$2 [L]
I also tried
RewriteRule ^calendar/([0-9]+)$/([0-9]+)$ pages/calendar.php?month=$1&year=$2 [L]
.htaccess file
RewriteEngine On
RewriteBase /researchportal/
RewriteRule ^/calendar/([0-9]+)$ index.php?p=calendar [QSA,L]
RewriteRule ^users/login /researchportal/pages/login.php [L]
RewriteRule ^users/logout /researchportal/pages/logout.php [L]
RewriteRule ^users/register logout.php [L]
RewriteRule ^profile/([0-9]+)$ index.php?p=profile&usr_id=$1 [QSA,L]
RewriteRule ^profile/edit/([0-9]+)$ index.php?p=edit&usr_id=$1 [L]
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?p=$1 [L]
^calendar/([0-9]+)$/([0-9]+)$
Why are you ending ( $ ) it twice?
^ starts and expression and $ ends it. There is no reason to have neither in the middle of an expression.
RewriteRule ^calendar/([0-9]+)/([0-9]+)$ pages/calendar.php?month=$1&year=$2 [L]
Should work better. If you for some reason would also want some query variables in the url, you can replace [L] with [L,QSA] aswell.
I think the problem is because you have an additional $ character.
RewriteRule ^calendar/([0-9]+) *$* /([0-9]+)$ index.php?p=calendar&month=$1&year=$2 [L]

Categories